stroke-dasharray 表现属性定义了用于绘制形状轮廓的虚线段和间隙的排列形式。
[!NOTE] 作为一个表现属性,
stroke-dasharray可以用作 CSS 属性。
你可以将此属性与以下 SVG 元素一起使用:
- circle
- ellipse
- path
- line
- polygon
- polyline
- rect
- text
- textPath
- tspan
示例
html,
body,
svg {
height: 100%;
}
<svg viewBox="0 0 30 12" xmlns="http://www.w3.org/2000/svg">
<style>
line {
stroke: black;
}
</style>
<line x1="0" y1="1" x2="30" y2="1" />
<line x1="0" y1="3" x2="30" y2="3" stroke-dasharray="4" />
<line x1="0" y1="5" x2="30" y2="5" stroke-dasharray="4 1" />
<line x1="0" y1="7" x2="30" y2="7" stroke-dasharray="4 1 2" />
<line x1="0" y1="9" x2="30" y2="9" stroke-dasharray="4 1 2 3" />
<line x1="0" y1="11" x2="30" y2="11" stroke-dasharray="0 4 0" />
</svg>
示例
使用说明
<table class="properties"> <tbody> <tr> <th scope="row">值</th> <td><code>none</code> | <code><dasharray></code></td> </tr> <tr> <th scope="row">默认值</th> <td><code>none</code></td> </tr> <tr> <th scope="row">动画性</th> <td>是</td> </tr> </tbody> </table>
- <dasharray>
-
: 以逗号或空格分隔的
<length>和<percentage>列表,用于定义交替的虚线段和间隙的长度。如果提供了奇数个值,则重复该列表以产生偶数个值,因此
5,3,2等价于5,3,2,5,3,2。
-
规范
浏览器兼容性
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
