CKTIS / CSS
CSS-Eigenschaft `mask-image`
`mask-image` wählt für jede Ebene kein Bild, ein CSS-Bild wie einen Verlauf oder eine URL zu einem Bild beziehungsweise SVG-Element `<mask>`.
Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review
Syntax
<mask-reference>#mask-image wählt für jede Ebene kein Bild, ein CSS-Bild wie einen Verlauf oder eine URL zu einem Bild beziehungsweise SVG-Element <mask>.
Das Chromium-Rasterbeispiel vergleicht vier Quellen: Ein einzelnes none lässt die Probe bei Alpha 255, der Verlauf ergibt 255/0 an seiner Grenze, eine gültige URL zu einer SVG-Halbmaske ebenfalls 255/0, und ein transparentes Bild per URL ergibt 0.
Grammatik: <mask-reference>#.
Anfangswert ist none. In einer mehrschichtigen Liste belegt none dennoch eine transparent-schwarze Ebene und kann die Komposition beeinflussen. Ein leeres Bild, Downloadfehler, fehlende Referenz oder nicht unterstützte Quelle wird ebenso transparent schwarz, statt das Element freizugeben. Andere mask-*-Listen werden an die Zahl der mask-image-Einträge angepasst; ein Wert ungleich none erzeugt einen Stapelkontext.
Beispiele
<!doctype html><meta charset="utf-8"><svg id="stage" xmlns="http://www.w3.org/2000/svg" width="150" height="20"><defs><mask id="half" maskUnits="userSpaceOnUse" x="80" y="0" width="30" height="20" mask-type="alpha"><rect x="80" width="15" height="20" fill="white"/></mask></defs><rect id="plain" width="30" height="20" fill="purple" style="mask-image:none"/><rect id="gradient" x="40" width="30" height="20" fill="purple" style="mask-image:linear-gradient(to right,black 0 50%,transparent 50%)"/><rect id="linked" x="80" width="30" height="20" fill="purple" style="mask-image:url(#half);mask-mode:alpha"/><rect id="missing" x="120" width="30" height="20" fill="purple" style="mask-image:url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221%22%20height%3D%221%22%2F%3E)"/></svg><pre id="result"></pre><script>
const rasterize=svg=>new Promise((resolve,reject)=>{const image=new Image();image.onload=()=>{const canvas=document.createElement('canvas');canvas.width=Number(svg.getAttribute('width'));canvas.height=Number(svg.getAttribute('height'));const context=canvas.getContext('2d');context.drawImage(image,0,0);resolve(context)};image.onerror=()=>reject(new Error('SVG rasterization failed'));image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(new XMLSerializer().serializeToString(svg))});
const alpha=(context,x,y)=>context.getImageData(x,y,1,1).data[3];
(async()=>{const context=await rasterize(stage),none=alpha(context,15,10),gL=alpha(context,45,10),gR=alpha(context,65,10),uL=alpha(context,85,10),uR=alpha(context,105,10),transparent=alpha(context,135,10),computed=getComputedStyle(gradient).maskImage;if(none<250||gL<250||gR>5||uL<250||uR>5||transparent>5||!computed.startsWith('linear-gradient'))throw new Error('mask-image source boundary mismatch '+[none,gL,gR,uL,uR,transparent,computed]);result.textContent='none='+none+'; gradient='+gL+'/'+gR+'; url='+uL+'/'+uR+'; transparent-url='+transparent+'; computed-gradient=true'})().catch(error=>result.textContent='ERROR:'+error.message);
</script>Ergebnis
none=255; gradient=255/0; url=255/0; transparent-url=0; computed-gradient=true
Das Beispiel lief lokal in einer isolierten Chrome-Sitzung ohne Netzwerk; das Ergebnis stammt aus der CSS-API des Browsers.