SVG 筆觸屬性
SVG 筆觸屬性
SVG 提供了廣泛的筆畫屬性。在本章中,我們將討論以下內容:
stroke
stroke-width
stroke-linecap
stroke-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>