stroke-dashoffset 是一种表现属性,它定义了虚线与路径起点之间的偏移量。
[!NOTE] 作为一个表现属性,
stroke-dashoffset可以用作 CSS 属性。
你可以将此属性与以下 SVG 元素一起使用:
- circle
- ellipse
- path
- line
- polygon
- polyline
- rect
- text
- textPath
- tspan
示例
html,
body,
svg {
height: 100%;
}
<svg viewBox="-3 0 33 10" xmlns="http://www.w3.org/2000/svg">
<line x1="0" y1="1" x2="30" y2="1" stroke="black" />
<line x1="0" y1="3" x2="30" y2="3" stroke="black" stroke-dasharray="3 1" />
<line
x1="0"
y1="5"
x2="30"
y2="5"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="3" />
<line
x1="0"
y1="7"
x2="30"
y2="7"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="-3" />
<line
x1="0"
y1="9"
x2="30"
y2="9"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="1" />
<path d="M0,5 h-3 M0,7 h3 M0,9 h-1" stroke="rgb(255 0 0 / 50%)" />
</svg>
示例
使用说明
<table class="properties"> <tbody> <tr> <th scope="row">值</th> <td> <strong ><a href="/zh-CN/docs/Web/SVG/Guides/Content_type#percentage" ><percentage></a ></strong > | <strong ><a href="/zh-CN/docs/Web/SVG/Guides/Content_type#length" ><length></a ></strong > </td> </tr> <tr> <th scope="row">默认值</th> <td><code>0</code></td> </tr> <tr> <th scope="row">可动画化</th> <td>是</td> </tr> </tbody> </table>
偏移量的计算通常基于 pathLength,但如果使用 <percentage> 值,那么将根据当前视口的百分比进行计算。
规范
浏览器兼容性
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
