このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

maskContentUnits

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月⁩.

maskContentUnits 属性は、 <mask> 要素のコンテンツに使用する座標系を示します。

この属性は、次の SVG 要素で使用することができます。

html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <mask id="myMask1" maskContentUnits="userSpaceOnUse">
    <rect fill="black" x="0" y="0" width="100%" height="100%" />
    <circle fill="white" cx="50" cy="50" r="35" />
  </mask>

  <mask id="myMask2" maskContentUnits="objectBoundingBox">
    <rect fill="black" x="0" y="0" width="100%" height="100%" />
    <circle fill="white" cx=".5" cy=".5" 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> では、maskContentUnits は、要素のコンテンツに使用されている座標系を定義します。

userSpaceOnUse | objectBoundingBox
既定値 userSpaceOnUse
アニメーション
userSpaceOnUse

この値は、この <mask> 要素内のすべての座標が、マスクの作成時に定義されたユーザー座標系を参照することを示します。

objectBoundingBox

この値は、この <mask> 要素内のすべての座標が、マスクが適用される要素の境界ボックスを基準としていることを示します。境界ボックスは、<mask> のコンテンツが "0 0 1 1" viewBox に結び付けられている場合と同じと考えることができます。

仕様書

Specification
CSS Masking Module Level 1
# element-attrdef-mask-maskcontentunits

ブラウザーの互換性