stroke-dashoffset

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 stroke-dashoffset ist ein Präsentationsattribut, das einen Versatz bei der Darstellung des zugehörigen Dash-Arrays definiert.

Hinweis: Als ein Präsentationsattribut hat stroke-dashoffset auch ein entsprechendes CSS-Attribut: stroke-dashoffset. Wenn beide angegeben sind, hat das CSS-Attribut Vorrang.

Sie können dieses Attribut mit den folgenden SVG-Elementen verwenden:

Beispiel

html
<svg viewBox="-3 0 33 10" xmlns="http://www.w3.org/2000/svg">
  <!-- No dash array -->
  <line x1="0" y1="1" x2="30" y2="1" stroke="black" />

  <!-- No dash offset -->
  <line x1="0" y1="3" x2="30" y2="3" stroke="black" stroke-dasharray="3 1" />

  <!--
  The start of the dash array computation
  is pulled by 3 user units
  -->
  <line
    x1="0"
    y1="5"
    x2="30"
    y2="5"
    stroke="black"
    stroke-dasharray="3 1"
    stroke-dashoffset="3" />

  <!--
  The start of the dash array computation
  is pushed by 3 user units
  -->
  <line
    x1="0"
    y1="7"
    x2="30"
    y2="7"
    stroke="black"
    stroke-dasharray="3 1"
    stroke-dashoffset="-3" />

  <!--
  The start of the dash array computation
  is pulled by 1 user units which ends up
  in the same rendering as the previous example
  -->
  <line
    x1="0"
    y1="9"
    x2="30"
    y2="9"
    stroke="black"
    stroke-dasharray="3 1"
    stroke-dashoffset="1" />

  <!--
  the following red lines highlight the
  offset of the dash array for each line
  -->
  <path d="M0,5 h-3 M0,7 h3 M0,9 h-1" stroke="rgb(255 0 0 / 50%)" />
</svg>

Nutzungshinweise

Wert <percentage> | <length>
Default-Wert 0
Animationsfähig Ja

Der Versatz wird normalerweise in Benutzereinheiten ausgedrückt, die gegen die pathLength aufgelöst werden. Wenn jedoch ein <percentage> verwendet wird, wird der Wert als Prozentsatz des aktuellen Ansichtsfensters aufgelöst.

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# StrokeDashoffsetProperty

Browser-Kompatibilität

Siehe auch