stroke-dasharray

stroke-dasharray attribute is a presentation attribute defining the pattern of dashes and gaps used to paint the outline of the shape;

注意: As a presentation attribute,  stroke-dasharray can be used as a CSS property.

You can use this attribute with the following SVG elements:

范例

<svg viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg">
  <!-- No dashes nor gaps -->
  <line x1="0" y1="1" x2="30" y2="1" stroke="black" />
  <!-- Dashes and gaps of the same size -->
  <line x1="0" y1="3" x2="30" y2="3" stroke="black"
          stroke-dasharray="4" />
  <!-- Dashes and gaps of different sizes -->
  <line x1="0" y1="5" x2="30" y2="5" stroke="black"
          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="black"
          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="black"
          stroke-dasharray="4 1 2 3" />
</svg>

					

用法注意事项

none | <dasharray>
默认值 none
Animatable Yes
<dasharray>

A list of comma and/or white space separated <length> s and <percentage> s that specify the lengths of alternating dashes and gaps.

If an odd number of values is provided, then the list of values is repeated to yield an even number of values. Thus, 5,3,2 相当于 5,3,2,5,3,2 .

浏览器兼容性

BCD tables only load in the browser

规范

规范 状态 注释
Scalable Vector Graphics (SVG) 2
The definition of 'stroke-dasharray' in that specification.
候选推荐 Definition for shapes and texts
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'stroke-dasharray' in that specification.
推荐 Initial definition for shapes and texts

Found a problem with this page?

最后修改: , 由 MDN 贡献者