stroke-width

Baseline 已广泛支持

此功能已经成熟,并可在许多设备和浏览器版本上使用。自 ⁨2020 年 3 月⁩起,它已在各浏览器中推出。

stroke-width 属性是一个表示属性,用于定义将应用于形状描边的宽度。它适用于任何 SVG 形状或文本内容元素,但作为一个继承属性,它也可以应用于 <g> 等元素,并对后代元素的描边产生预期效果。

注意: 作为一个表示属性,stroke-width 还有一个 CSS 属性对应项:stroke-width。当两者都被指定时,CSS 属性具有更高的优先级。

你可以将此属性与以下 SVG 元素一起使用

示例

html
<svg viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg">
  <!-- Default stroke width: 1 -->
  <circle cx="5" cy="5" r="3" stroke="green" />

  <!-- Stroke width as a number -->
  <circle cx="15" cy="5" r="3" stroke="green" stroke-width="3" />

  <!-- Stroke width as a percentage -->
  <circle cx="25" cy="5" r="3" stroke="green" stroke-width="2%" />
</svg>

用法说明

<length> | <percentage>
默认值 1px
可动画的

注意: 百分比值始终计算为归一化 viewBox 对角线长度的百分比。

规范

规范
Scalable Vector Graphics (SVG) 2
# StrokeWidth

浏览器兼容性

另见