SVG 笔触属性
SVG 笔触属性
SVG 提供了广泛的笔画属性。在本章中,我们将讨论以下内容:
strokestroke-widthstroke-linecapstroke-dasharray
所有笔触属性都可用于任何类型的线条、文本和元素的轮廓(如圆形)。
SVG stroke 属性
stroke 属性定义线条、文本或元素的轮廓的颜色:
这是 SVG 代码:
<svg height="80" width="300">
<g fill="none">
<path stroke="red" d="M5 20 l215 0" />
<path stroke="black" d="M5 40 l215 0" />
<path stroke="blue" d="M5 60 l215 0" />
</g>
</svg>
SVG stroke-width 属性
stroke-width 属性定义线条、文本或元素的轮廓的粗细:
这是 SVG 代码:
<svg height="80" width="300">
<g fill="none" stroke="black">
<path stroke-width="2" d="M5 20 l215 0" />
<path stroke-width="4" d="M5 40 l215 0" />
<path stroke-width="6" d="M5 60 l215 0" />
</g>
</svg>
SVG stroke-linecap 属性
stroke-linecap 属性定义开放路径的不同类型的终点:
这是 SVG 代码:
<svg height="80" width="300">
<g fill="none" stroke="black" stroke-width="6">
<path stroke-linecap="butt" d="M5 20 l215 0" />
<path stroke-linecap="round" d="M5 40 l215 0" />
<path stroke-linecap="square" d="M5 60 l215 0" />
</g>
</svg>
SVG stroke-dasharray 属性
stroke-dasharray 属性用于创建虚线:
这是 SVG 代码:
<svg height="80" width="300">
<g fill="none" stroke="black" stroke-width="4">
<path stroke-dasharray="5,5" d="M5 20 l215 0" />
<path stroke-dasharray="10,10" d="M5 40 l215 0" />
<path stroke-dasharray="20,10,5,5,5,10" d="M5 60 l215 0" />
</g>
</svg>