clip-rule
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Das Attribut clip-rule
gilt nur für Grafikelemente, die sich innerhalb eines <clipPath>
-Elements befinden. Das Attribut clip-rule
funktioniert im Wesentlichen wie das Attribut fill-rule
, mit dem Unterschied, dass es auf Definitionen von <clipPath>
angewendet wird.
Hinweis:
Als Präsentationsattribut hat clip-rule
auch ein entsprechendes CSS-Property: clip-rule
. Wenn beide angegeben sind, hat das CSS-Property Vorrang.
Der folgende Codeausschnitt bewirkt, dass eine "evenodd"-Clipping-Regel auf den Clipping-Pfad angewendet wird, da clip-rule
auf dem <path>
-Element spezifiziert ist, das die Clipping-Form definiert:
<g>
<clipPath id="MyClip">
<path d="..." clip-rule="evenodd" />
</clipPath>
<rect clip-path="url(#MyClip)" ... />
</g>
Hingegen wird der folgende Codeausschnitt keine "evenodd"-Clipping-Regel anwenden, da clip-rule
auf dem referenzierenden Element angegeben ist und nicht auf dem Objekt, das die Clipping-Form definiert:
<g>
<clipPath id="MyClip">
<path d="..." />
</clipPath>
<rect clip-path="url(#MyClip)" clip-rule="evenodd" ... />
</g>
Verwendungshinweise
Beispiel
<svg
width="100"
viewBox="0 0 100 90"
xmlns="http://www.w3.org/2000/svg"
version="1.1">
<!-- Define star path -->
<defs>
<path d="M50,0 21,90 98,35 2,35 79,90z" id="star" />
</defs>
<!-- Left: evenodd -->
<clipPath id="emptyStar">
<use href="#star" clip-rule="evenodd" />
</clipPath>
<rect clip-path="url(#emptyStar)" width="50" height="90" fill="blue" />
<!-- Right: nonzero -->
<clipPath id="filledStar">
<use href="#star" clip-rule="nonzero" />
</clipPath>
<rect clip-path="url(#filledStar)" width="50" height="90" x="50" fill="red" />
</svg>
Elemente
Die folgenden Elemente können das Attribut clip-rule
verwenden, allerdings nur, wenn sie sich innerhalb eines <clipPath>
-Elements befinden.
Spezifikationen
Specification |
---|
CSS Masking Module Level 1 # the-clip-rule |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
clip-rule |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
Siehe auch
<clipPath>
- CSS
clip-rule
-Eigenschaft