SVG代表可縮放矢量圖形。它可以用於在HTML畫布中製作圖形和動畫。 <pattern>元素用於用由圖像組成的圖案填充形狀。它以平鋪方式填充形狀。
用法:
<pattern> . . . </pattern>
屬性:
- patternUnits:它定義了x,y,高度和寬度的坐標。
- patternContentUnits:它定義了圖案的區域。
- preserveAspectRatio:它顯示了一個帶有viewBox的元素,該元素給出了一個長寬比,必須適合具有不同長寬比的視口。
- xlink:href:它定義了對資源的參考IRI。
範例1:
HTML
<!DOCTYPE html>
<html>
<body>
<svg width="200" height="200">
<defs>
<pattern id="pattern" x="0" y="0"
width="10" height="10"
patternUnits="userSpaceOnUse">
<circle cx="10" cy="10" r="10"
style="stroke:lightgreen;
fill:white" />
</pattern>
</defs>
<rect x="10" y="10" width="100"
height="100" style="stroke:#000000;
fill:url(#pattern);" />
<g fill="#FFFFFF" stroke="black"
font-size="12" font-family="Verdana">
<text x="13" y="65">
GeeksForGeeks
</text>
</svg>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html>
<body>
<svg width="300" height="350">
<defs>
<pattern id="in" x="2" y="2"
width="6" height="6"
patternUnits="userSpaceOnUse">
<rect x="2" y="2" width="4"
height="8" stroke="green"
fill="red" />
</pattern>
<pattern id="out" x="13" y="13"
width="50" height="50"
patternUnits="userSpaceOnUse">
<circle cx="4" cy="4" r="18"
stroke="black"
stroke-width="4px"
fill="url(#in)" />
</pattern>
</defs>
<rect x="1" y="5" width="200"
height="200" stroke="green"
fill="url(#out)" />
</svg>
</body>
</html>
輸出:
相關用法
- SVG <marker>用法及代碼示例
- SVG <desc>用法及代碼示例
- SVG <a>用法及代碼示例
- SVG <clipPath>用法及代碼示例
- SVG <title>用法及代碼示例
- SVG <animateMotion>用法及代碼示例
- SVG <animate>用法及代碼示例
- SVG <g>用法及代碼示例
- SVG <textPath>用法及代碼示例
- SVG <tspan>用法及代碼示例
- SVG <use>用法及代碼示例
- SVG <symbol>用法及代碼示例
- SVG <foreignObject>用法及代碼示例
- SVG <hatch>用法及代碼示例
- SVG <set>用法及代碼示例
- SVG <feFlood>用法及代碼示例
注:本文由純淨天空篩選整理自epistler_999大神的英文原創作品 SVG <pattern> Element。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。