stroke-dasharray
stroke-dasharray
属性是定义用于绘制形状轮廓的虚线和间隙模式的呈现属性。
注意: 作为一个呈现属性,stroke-dasharray
还有一个对应的 CSS 属性:stroke-dasharray
。当同时指定两者时,CSS 属性具有优先权。
你可以将此属性与以下 SVG 元素一起使用
示例
html
<svg viewBox="0 0 30 12" xmlns="http://www.w3.org/2000/svg">
<style>
line {
stroke: black;
}
</style>
<!-- No dashes nor gaps -->
<line x1="0" y1="1" x2="30" y2="1" />
<!-- Dashes and gaps of the same size -->
<line x1="0" y1="3" x2="30" y2="3" stroke-dasharray="4" />
<!-- Dashes and gaps of different sizes -->
<line x1="0" y1="5" x2="30" y2="5" stroke-dasharray="4 1" />
<!-- Dashes and gaps of various sizes with an odd number of values -->
<line x1="0" y1="7" x2="30" y2="7" stroke-dasharray="4 1 2" />
<!-- Dashes and gaps of various sizes with an even number of values -->
<line x1="0" y1="9" x2="30" y2="9" stroke-dasharray="4 1 2 3" />
<!-- Dashes starting with a gap -->
<line x1="0" y1="11" x2="30" y2="11" stroke-dasharray="0 4 0" />
</svg>
用法说明
值 | none | <dasharray> |
---|---|
默认值 | none |
可动画的 | 是 |
- <dasharray>
-
由逗号和/或空格分隔的
<length>
和<percentage>
列表,用于指定交替的虚线和间隙的长度。如果提供了奇数个值,则该值列表将重复以产生偶数个值。因此,
5,3,2
等同于5,3,2,5,3,2
。
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # StrokeDashing |
浏览器兼容性
加载中…
另见
- CSS
stroke-dasharray
属性