stroke
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2020å¹´7æâ©.
* Some parts of this feature may have varying levels of support.
stroke æ¯ä¸ä¸ªè¡¨ç°å±æ§ï¼å®å®ä¹äºå¾å½¢çå¤è½®å»çé¢è²ï¼æè
æ¯ä»»ä½ SVG ç»ç»æ¹å¼ï¼å¦æ¸åæå¾æ¡ï¼ã
夿³¨ï¼ä½ä¸ºä¸ä¸ªè¡¨ç°å±æ§ï¼stroke å¯ä»¥ç¨ä½ CSS 屿§ãåè§ stroke 以äºè§£æ´å¤ä¿¡æ¯ã
ä½ å¯ä»¥å°æ¤å±æ§ä¸ä»¥ä¸ SVG å ç´ ä¸èµ·ä½¿ç¨ï¼
示ä¾
>åºç¡é¢è²åæ¸åè²æè¾¹
<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg">
<!-- 使ç¨åä¸é¢è²æè¾¹ -->
<circle cx="5" cy="5" r="4" fill="none" stroke="green" />
<!-- ä½¿ç¨æ¸åè²æè¾¹ -->
<defs>
<linearGradient id="myGradient">
<stop offset="0%" stop-color="green" />
<stop offset="100%" stop-color="white" />
</linearGradient>
</defs>
<circle cx="15" cy="5" r="4" fill="none" stroke="url(#myGradient)" />
</svg>
è¾åºå¦ä¸ï¼
context-stroke 示ä¾
å¨è¿ä¸ªç¤ºä¾ä¸ï¼æä»¬ä½¿ç¨ <path> å
ç´ å®ä¹äºä¸ä¸ªå½¢ç¶çå¾å½¢ï¼æ¯ä¸ªå¾å½¢é½è®¾ç½®äºä¸åç stroke å fill é¢è²ãæä»¬è¿éè¿ <marker> å
ç´ å° <circle> å
ç´ å®ä¹ä¸ºæ è®°ãæ¯ä¸ªå¾å½¢é½éè¿ marker CSS 屿§åºç¨äºæ è®°ã
<circle> å
ç´ ä¸è®¾ç½®äº stroke="context-stroke" å fill="context-fill"ãå 为å®è¢«è®¾ç½®ä¸ºå¾å½¢çä¸ä¸ææ è®°ï¼æä»¥è¿äºå±æ§ä¼å¯¼è´å®å¨åç§æ
åµä¸é½ä¼ç»§æ¿è®¾ç½®å¨ <path> å
ç´ ä¸ç fill å strokeã
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 90">
<style>
path {
stroke-width: 2px;
marker: url(#circle);
}
</style>
<path d="M 10 44.64 L 30 10 L 70 10 L 90 44.64 L 70 79.28 L 30 79.28 Z"
stroke="red" fill="orange" />
<path d="M 100 44.64 L 80 10 L 120 10 L 140 44.64 L 120 79.28 L 80 79.28 Z"
stroke="green" fill="lightgreen" />
<path d="M 150 44.64 L 130 10 L 170 10 L 190 44.64 L 170 79.28 L 130 79.28 Z"
stroke="blue" fill="lightblue" />
<marker id="circle" markerWidth="12" markerHeight="12"
refX="6" refY="6" markerUnits="userSpaceOnUse">
<circle cx="6" cy="6" r="3" stroke-width="2"
stroke="context-stroke" fill="context-fill" />
</marker>
</svg>
è¾åºå¦ä¸ï¼
夿³¨ï¼å½å
ç´ è¢« <use> å
ç´ å¼ç¨æ¶ï¼å
ç´ è¿å¯ä»¥ä½¿ç¨ context-stroke å context-fill æ¥ç»§æ¿ stroke å fill çå¼ã
ç¨æ³
| å¼ | <paint> |
|---|---|
| é»è®¤å¼ | none |
| å¨ç»æ§ | æ¯ |
è§è
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2 > # SpecifyingStrokePaint > |