stroke-linecap
**stroke-linecap** 屬性是一個表示屬性,用於定義在描邊開放子路徑時,子路徑末端使用的形狀。
**注意:** 作為表示屬性,stroke-linecap 可以用作 CSS 屬性。更多資訊,請參見 stroke-linecap。
您可以將此屬性與以下 SVG 元素一起使用
示例
html
<svg viewBox="0 0 6 6" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the (default) "butt" value -->
<line x1="1" y1="1" x2="5" y2="1" stroke="black" stroke-linecap="butt" />
<!-- Effect of the "round" value -->
<line x1="1" y1="3" x2="5" y2="3" stroke="black" stroke-linecap="round" />
<!-- Effect of the "square" value -->
<line x1="1" y1="5" x2="5" y2="5" stroke="black" stroke-linecap="square" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4 M1,3 h4 M1,5 h4" stroke="pink" stroke-width="0.025" />
</svg>
用法說明
| 值 | butt | round | square |
|---|---|
| 預設值 | butt |
| 可動畫 | 離散 |
butt
butt 值表示每個子路徑的描邊不會超出其兩個端點。在零長度子路徑上,路徑將根本不渲染。
示例
html
<svg viewBox="0 0 6 4" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the "butt" value -->
<path d="M1,1 h4" stroke="black" stroke-linecap="butt" />
<!-- Effect of the "butt" value on a zero length path -->
<path d="M3,3 h0" stroke="black" stroke-linecap="butt" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4" stroke="pink" stroke-width="0.025" />
<circle cx="1" cy="1" r="0.05" fill="pink" />
<circle cx="5" cy="1" r="0.05" fill="pink" />
<circle cx="3" cy="3" r="0.05" fill="pink" />
</svg>
round
round 值表示在每個子路徑的末端,描邊將延伸出一個半圓,其直徑等於描邊寬度。在零長度子路徑上,描邊由以子路徑點為中心的完整圓構成。
示例
html
<svg viewBox="0 0 6 4" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the "round" value -->
<path d="M1,1 h4" stroke="black" stroke-linecap="round" />
<!-- Effect of the "round" value on a zero length path -->
<path d="M3,3 h0" stroke="black" stroke-linecap="round" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4" stroke="pink" stroke-width="0.025" />
<circle cx="1" cy="1" r="0.05" fill="pink" />
<circle cx="5" cy="1" r="0.05" fill="pink" />
<circle cx="3" cy="3" r="0.05" fill="pink" />
</svg>
square
square 值表示在每個子路徑的末端,描邊將延伸出一個矩形,其寬度等於描邊寬度的一半,高度等於描邊寬度。在零長度子路徑上,描邊由一個正方形構成,其寬度等於描邊寬度,以子路徑點為中心。
示例
html
<svg viewBox="0 0 6 4" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the "square" value -->
<path d="M1,1 h4" stroke="black" stroke-linecap="square" />
<!-- Effect of the "square" value on a zero length path -->
<path d="M3,3 h0" stroke="black" stroke-linecap="square" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4" stroke="pink" stroke-width="0.025" />
<circle cx="1" cy="1" r="0.05" fill="pink" />
<circle cx="5" cy="1" r="0.05" fill="pink" />
<circle cx="3" cy="3" r="0.05" fill="pink" />
</svg>
規範
| 規範 |
|---|
| 可縮放向量圖形 (SVG) 2 # LineCaps |
瀏覽器相容性
BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。