CKTIS / CSS
polygon() — Polygon aus Koordinatenpaaren
`polygon()` verbindet Längen-Prozent-Koordinatenpaare zu einer geschlossenen Grundform relativ zur Bezugsbox.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
polygon( <'fill-rule'>? [ round <length> ]?, [ <length-percentage> <length-percentage> ]# )polygon() verbindet Längen-Prozent-Koordinatenpaare zu einer geschlossenen Grundform relativ zur Bezugsbox.
polygon(0 0, 100% 0, 0 100%) ergibt in einer 100×60-Box die Innen-/Außenprobe 255/0; nach Verbreiterung auf 200×60 bleibt sie 255/0 und zeigt die Prozentskalierung. Gerundetes polygon(round 10px, 0 0, 100% 0, 0 100%) meldet Unterstützung true.
Grammatik: polygon( <'fill-rule'>? [ round <length> ]?, [ <length-percentage> <length-percentage> ]# ).
Die erste Prozentkoordinate bezieht sich auf die Breite, die zweite auf die Höhe; der UA verbindet stets den letzten mit dem ersten Eckpunkt. Die Füllregel ist standardmäßig nonzero; evenodd ändert das Innere selbstschneidender Figuren, und round rundet Ecken. Die Funktion dient clip-path und shape-outside. Polygoninterpolation verlangt gleiche Eckpunktzahl und Füllregel.
Beispiele
const render=async(value,width,height,points)=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="'+width+'" height="'+height+'"><foreignObject width="'+width+'" height="'+height+'"><div xmlns="http://www.w3.org/1999/xhtml" style="width:'+width+'px;height:'+height+'px;background:blue;clip-path:'+value+'"></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=width;canvas.height=height;const context=canvas.getContext('2d');context.drawImage(image,0,0);return points.map(([x,y])=>context.getImageData(x,y,1,1).data[3])};
const value='polygon(0 0, 100% 0, 0 100%)';
const small=await render(value,100,60,[[10,10],[80,40]]);
const wide=await render(value,200,60,[[100,10],[180,40]]);
const rounded=CSS.supports('clip-path','polygon(round 10px, 0 0, 100% 0, 0 100%)');
console.log('small-in/out='+small.join('/')+'; wide-in/out='+wide.join('/')+'; rounded-supported='+rounded);Ergebnis
small-in/out=255/0; wide-in/out=255/0; rounded-supported=true
`polygon()` verbindet Längen-Prozent-Koordinatenpaare zu einer geschlossenen Grundform relativ zur Bezugsbox.