patternContentUnits
patternContentUnits 屬性指示對 <pattern> 元素的內容使用哪個座標系。
您可以將此屬性與以下 SVG 元素一起使用
示例
html
<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
<!--
A pattern tile that content coordinates and values are
computed against the current coordinate user space.
Note that the size of the tile is computed against
the bounding box of the target element
-->
<pattern
id="p1"
width="20%"
height="20%"
patternContentUnits="userSpaceOnUse">
<circle cx="10" cy="10" r="10" />
</pattern>
<!--
A pattern tile that content coordinates and values are
computed against the bounding box of the target element.
Note that the size of the tile is also computed against
the bounding box of the target element
-->
<pattern
id="p2"
width="20%"
height="20%"
patternContentUnits="objectBoundingBox">
<circle cx=".1" cy=".1" r=".1" />
</pattern>
<!-- Left square with user space tiles -->
<rect x="10" y="10" width="80" height="80" fill="url(#p1)" />
<!-- Right square with bounding box tiles -->
<rect x="110" y="10" width="80" height="80" fill="url(#p2)" />
</svg>
pattern
對於 <pattern>,patternContentUnits 定義用於元素內容的座標系。
| 值 | userSpaceOnUse | objectBoundingBox |
|---|---|
| 預設值 | userSpaceOnUse |
| 可動畫 | 是 |
userSpaceOnUse-
此值指示
<pattern>元素內的所有座標都引用在建立圖案塊時定義的使用者座標系。 objectBoundingBox-
此值指示
<pattern>元素內的所有座標都相對於應用圖案的元素的邊界框。邊界框可以被認為與<pattern>的內容繫結到圖案塊寬度和高度為 100% 的“0 0 1 1”viewBox相同。
規範
| 規範 |
|---|
| 可縮放向量圖形 (SVG) 2 # PatternElementPatternContentUnitsAttribute |
瀏覽器相容性
BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。