大网数据广告活动
Web 标准与前端开发

stroke-dasharray

· 52CE 我爱测

**`stroke-dasharray`** 表现属性定义了用于绘制形状轮廓的虚线段和间隙的排列形式。

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。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。