このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
maskUnits
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年1月.
maskUnits 属性は、<mask> 要素の幾何プロパティに使用する座標系を示します。
この属性は、次の SVG 要素で使用することができます。
In this article
例
html,body,svg { height: 100%;}html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <mask 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 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 x="0" y="0" width="45" height="45" /> <rect x="0" y="55" width="45" height="45" /> <rect x="55" y="55" width="45" height="45" /> <rect 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> |