KennisbankExamencentrum
NL · NLNederlands (Nederland)
Taal kiezen13

CKTIS / CSS

path() — vorm uit SVG-padgegevens

`path()` maakt een basisvorm uit één `SVG`-padgegevensreeks en een optionele vulregel.

Versie: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

path( [ <'fill-rule'>, ]? <string> )

path() maakt een basisvorm uit één SVG-padgegevensreeks en een optionele vulregel.

Het voorbeeld knipt een doos met path("M 10 10 L 90 10 L 50 90"): de binnenpixel en impliciet gesloten randpixel hebben alfa 255, de buitenpixel 0. Leeg path("") en procentgegevens path("M 0 0 L 100% 0 L 0 100%") geven false.

Grammatica: path( [ <'fill-rule'>, ]? <string> ).

De reeks moet geldige, niet-lege SVG-padgegevens bevatten; voor eigenschappen met een gesloten lus voegt de UA sluiting toe. De standaardregel is nonzero, met evenodd als alternatief. Coördinaten erven SVG-beperkingen en gebruiken feitelijk px: percentages en variabelen in delen binnen de reeks ontbreken. Gebruik shape() voor responsieve CSS-eenheden; interpolatie vereist gelijke opdrachtvolgorde en vulregel.

Voorbeelden

const render=async value=>{const safe=value.replaceAll('"','&quot;');const svg='<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><foreignObject width="100" height="100"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100px;height:100px;background:red;clip-path:'+safe+'"></div></foreignObject></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=100;const context=canvas.getContext('2d');context.drawImage(image,0,0);const alpha=(x,y)=>context.getImageData(x,y,1,1).data[3];return[alpha(50,40),alpha(15,80),alpha(50,85)]};
const pixels=await render('path("M 10 10 L 90 10 L 50 90")');
const empty=CSS.supports('clip-path','path("")');
const percentage=CSS.supports('clip-path','path("M 0 0 L 100% 0 L 0 100%")');
console.log('inside='+pixels[0]+'; outside='+pixels[1]+'; implicit-close='+pixels[2]+'; empty-path='+empty+'; percentage-data='+percentage);

Resultaat

inside=255; outside=0; implicit-close=255; empty-path=false; percentage-data=false

`path()` maakt een basisvorm uit één `SVG`-padgegevensreeks en een optionele vulregel.

Bronnen