maskUnits
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
例
html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<mask
id="myMask1"
maskUnits="userSpaceOnUse"
x="20%"
y="20%"
width="60%"
height="60%">
<rect fill="black" x="0" y="0" width="100%" height="100%" />
<circle fill="white" cx="50" cy="50" r="35" />
</mask>
<mask
id="myMask2"
maskUnits="objectBoundingBox"
x="20%"
y="20%"
width="60%"
height="60%">
<rect fill="black" x="0" y="0" width="100%" height="100%" />
<circle fill="white" cx="50" cy="50" r="35" />
</mask>
<!-- Some reference rect to materialized the mask -->
<rect id="r1" x="0" y="0" width="45" height="45" />
<rect id="r2" x="0" y="55" width="45" height="45" />
<rect id="r3" x="55" y="55" width="45" height="45" />
<rect id="r4" x="55" y="0" width="45" height="45" />
<!-- The first 3 rect are masked with useSpaceOnUse units -->
<use mask="url(#myMask1)" href="#r1" fill="red" />
<use mask="url(#myMask1)" href="#r2" fill="red" />
<use mask="url(#myMask1)" href="#r3" fill="red" />
<!-- The last rect is masked with objectBoundingBox units -->
<use mask="url(#myMask2)" href="#r4" fill="red" />
</svg>
mask
<mask>
では、 maskUnits
は要素の幾何属性 (x
、y
、width
、height
) に使用される座標系を定義します。
値 | userSpaceOnUse | objectBoundingBox |
---|---|
既定値 | objectBoundingBox |
アニメーション | 可 |
userSpaceOnUse
-
この値は、幾何属性のすべての座標が、マスクの作成時に定義されたユーザー座標系を参照することを示します。
objectBoundingBox
-
この値は、幾何属性のすべての座標が、マスクが適用される要素の境界ボックスを小数またはパーセント値で表すことを示します。境界ボックスは、
<mask>
のコンテンツが"0 0 1 1"
viewBox
に結び付けられている場合と同じと考えることができます。
仕様書
Specification |
---|
CSS Masking Module Level 1 # element-attrdef-mask-maskunits |