stroke
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.
* Some parts of this feature may have varying levels of support.
Das stroke
-Attribut ist ein Präsentationsattribut, das die Farbe (oder einen SVG-Farbserver wie Verläufe oder Muster) definiert, mit der die Umrandung der Form gezeichnet wird.
Hinweis:
Als Präsentationsattribut hat stroke
auch ein entsprechendes CSS-Eigenschafts-Pendant: stroke
. Wenn beide spezifiziert sind, hat die CSS-Eigenschaft Vorrang.
Dieses Attribut kann mit den folgenden SVG-Elementen verwendet werden:
Beispiele
Grundlegende Farbe und Verlaufsstrich
<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg">
<!-- Basic color stroke -->
<circle cx="5" cy="5" r="4" fill="none" stroke="green" />
<!-- Stroke a circle with a gradient -->
<defs>
<linearGradient id="myGradient">
<stop offset="0%" stop-color="green" />
<stop offset="100%" stop-color="white" />
</linearGradient>
</defs>
<circle cx="15" cy="5" r="4" fill="none" stroke="url(#myGradient)" />
</svg>
Das Ergebnis sieht wie folgt aus:
context-stroke
-Beispiel
In diesem Beispiel definieren wir drei Formen mit Hilfe von <path>
-Elementen, die jeweils unterschiedliche stroke
- und fill
-Farben haben. Wir definieren auch ein <circle>
-Element als Marker mithilfe des <marker>
-Elements. Jeder Form wird der Marker über die marker
-CSS-Eigenschaft zugewiesen.
Das <circle>
-Element hat stroke="context-stroke"
und fill="context-fill"
gesetzt. Da es im Kontext der Formen als Marker festgelegt ist, bewirken diese Attribute, dass es die fill
- und stroke
-Werte des jeweiligen <path>
-Elements erbt.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 90">
<style>
path {
stroke-width: 2px;
marker: url(#circle);
}
</style>
<path d="M 10 44.64 L 30 10 L 70 10 L 90 44.64 L 70 79.28 L 30 79.28 Z"
stroke="red" fill="orange" />
<path d="M 100 44.64 L 80 10 L 120 10 L 140 44.64 L 120 79.28 L 80 79.28 Z"
stroke="green" fill="lightgreen" />
<path d="M 150 44.64 L 130 10 L 170 10 L 190 44.64 L 170 79.28 L 130 79.28 Z"
stroke="blue" fill="lightblue" />
<marker id="circle" markerWidth="12" markerHeight="12"
refX="6" refY="6" markerUnits="userSpaceOnUse">
<circle cx="6" cy="6" r="3" stroke-width="2"
stroke="context-stroke" fill="context-fill" />
</marker>
</svg>
Das Ergebnis sieht wie folgt aus:
Hinweis:
Elemente können ebenfalls context-stroke
und context-fill
verwenden, um stroke
- und fill
-Werte zu erben, wenn sie durch <use>
-Elemente referenziert werden.
Hinweise zur Verwendung
Wert | <paint> |
---|---|
Standardwert | none |
Animierbar | Ja |
Spezifikationen
Specification |
---|
Scalable Vector Graphics (SVG) 2 # SpecifyingStrokePaint |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
stroke | ||||||||||||
context-stroke value |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
Siehe auch
- CSS-
stroke
-Eigenschaft