圖案單位

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流瀏覽器均已支援。

patternUnits 屬性指示用於 <pattern> 元素的幾何屬性的座標系。

你可以將此屬性與以下 SVG 元素一起使用

示例

html
<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <!-- All geometry properties are relative to the current user space -->
  <pattern
    id="p1"
    x="12.5"
    y="12.5"
    width="25"
    height="25"
    patternUnits="userSpaceOnUse">
    <circle cx="10" cy="10" r="10" />
  </pattern>

  <!-- All geometry properties are relative to the target bounding box -->
  <pattern
    id="p2"
    x=".125"
    y=".125"
    width=".25"
    height=".25"
    patternUnits="objectBoundingBox">
    <circle cx="10" cy="10" r="10" />
  </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>

元素

你可以在下面部分描述的 SVG 元素中使用此屬性。

<pattern>

對於 <pattern>patternUnits 定義了元素幾何屬性(xywidthheight)所使用的座標系。

userSpaceOnUse | objectBoundingBox
預設值 objectBoundingBox
可動畫的
userSpaceOnUse

此值表示幾何屬性的所有座標均指圖案應用時定義的使用者座標系

objectBoundingBox

此值表示幾何屬性的所有座標均表示應用圖案的元素的邊界框的分數或百分比。邊界框可被視為與將 <pattern> 的內容繫結到 "0 0 1 1" viewBox 時相同。

規範

規範
Scalable Vector Graphics (SVG) 2
# PatternElementPatternUnitsAttribute

瀏覽器相容性