stroke-dashoffset
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2020å¹´3æâ©.
stroke-dashoffset æ¯ä¸ç§è¡¨ç°å±æ§ï¼å®å®ä¹äºè线ä¸è·¯å¾èµ·ç¹ä¹é´çåç§»éã
夿³¨ï¼ä½ä¸ºä¸ä¸ªè¡¨ç°å±æ§ï¼stroke-dashoffset å¯ä»¥ç¨ä½ CSS 屿§ã
ä½ å¯ä»¥å°æ¤å±æ§ä¸ä»¥ä¸ SVG å ç´ ä¸èµ·ä½¿ç¨ï¼
示ä¾
html
<svg viewBox="-3 0 33 10" xmlns="http://www.w3.org/2000/svg">
<!-- 没æè®¾ç½®ä¸ºè线 -->
<line x1="0" y1="1" x2="30" y2="1" stroke="black" />
<!-- 没æè®¾ç½®åç§»é -->
<line x1="0" y1="3" x2="30" y2="3" stroke="black" stroke-dasharray="3 1" />
<!-- è线æ£ååç§»äº 3 个åä½ -->
<line
x1="0"
y1="5"
x2="30"
y2="5"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="3" />
<!-- è线åååç§»äº 3 个åä½ -->
<line
x1="0"
y1="7"
x2="30"
y2="7"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="-3" />
<!-- è线æ£ååç§»äº 1 个åä½ï¼æç»æ¸²æç»æåä¸ä¸ä¸ªä¾åç¸å -->
<line
x1="0"
y1="9"
x2="30"
y2="9"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="1" />
<!-- åºä¸ççº¢çº¿çªæ¾äºæ¯è¡è线çåç§»é -->
<path d="M0,5 h-3 M0,7 h3 M0,9 h-1" stroke="rgb(255 0 0 / 50%)" />
</svg>
使ç¨è¯´æ
| å¼ | <percentage> | <length> |
|---|---|
| é»è®¤å¼ | 0 |
| å¯å¨ç»å | æ¯ |
åç§»éç计ç®é常åºäº pathLengthï¼ä½å¦æä½¿ç¨ <percentage> å¼ï¼é£ä¹å°æ ¹æ®å½åè§å£çç¾åæ¯è¿è¡è®¡ç®ã
è§è
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2 > # StrokeDashoffsetProperty > |