元件定義了一個圖形物件,該物件可以以重複的 x 和 y 坐標間隔(“平鋪”)重新繪製以覆蓋一個區域。
由其他圖形元件上的 fill 和/或 stroke 屬性引用,以使用引用的模式填充或描邊這些元件。
<svg viewBox="0 0 230 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="star" viewBox="0,0,10,10" width="10%" height="10%">
<polygon points="0,0 2,5 0,10 5,8 10,10 8,5 10,0 5,2"/>
</pattern>
</defs>
<circle cx="50" cy="60" r="50" fill="url(#star)"/>
<circle cx="120" cy="60" r="40" fill="none"
stroke-width="20" stroke="url(#star)"/>
</svg>
<pattern>可以製作透明背景的效果:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<pattern id="checkerPattern" patternUnits="userSpaceOnUse"
x="0" y="0" width="20" height="20" viewBox="0 0 10 10">
<rect x="0" y="0" width="10" height="10" fill="#fff">
<rect x="0" y="0" width="5" height="5" fill="#eee">
<rect x="5" y="5" width="5" height="5" fill="#eee">
</pattern>
</defs>
<rect width="100%" height="100%" x="0" y="0" stroke="#000"
fill="url(#checkerPattern)" style="pointer-events:none">
</svg>
SVG 拷貝 - <use>