



mask-repeatプロパティは、マスクレイヤーイメージの繰り返し方法を指定する際に使用します。
値にキーワードを1つだけ指定した場合には、水平方向と垂直方向の繰り返し方法となります。
半角スペース区切りでキーワードを2つ指定した場合には、1つ目は水平方向、2つ目は垂直方向の繰り返し方法となります。
mask-repeatプロパティに指定できるキーワードは、以下の通りです。
仕様ではmask-repeatプロパティの初期値は no-repeat とされていますが、webkit系ブラウザでは現在のところ初期値 repeat でサポートされているようです。
このページ内のサンプルでは、以下の80×80ピクセルの画像をマスクレイヤーとして使用します。
ハートの図形部分以外は透明にしてあります。

マスク処理対象となる要素は、以下の200×200ピクセルの画像です。

200×200ピクセルのマスク対象画像に対して、80×80ピクセルのマスクイメージのパターンをそのままのサイズで並べると、縦横に2個半並ぶことになります。
ただし、値に space や round を指定すると見栄えが良くなるように、マスクイメージの配置やパターンのサイズが自動調整されます。
■値
- repeat-x
- 水平方向にのみ繰り返す
- repeat-y
- 垂直方向にのみ繰り返す
- repeat
- 水平方向と垂直方向に繰り返す
- space
- マスクレイヤーイメージを繰り返す際、最初と最後のイメージが領域の端に接するようにスペースを空けて配置されます。結果としてパターンの途中で切れない見栄えとなります。
- round
- マスクレイヤーイメージを繰り返す際、イメージのサイズが調整されて配置されます。結果としてパターンの途中で切れない見栄えとなります。
- no-repeat
- 一度だけ配置されて、繰り返しません(初期値)
■初期値・適用対象・値の継承
- 初期値
- no-repeat
- 適用対象
- すべての要素。 SVGでは、defs要素とすべてのグラフィックス要素を除くコンテナ要素に適用される
- 値の継承
- しない
■使用例
CSSソースは外部ファイル(sample.css)に記述
img.sample0 {
mask-image: url(‘images/heart_s.png’);
}
img.sample1 {
mask-image: url(‘images/heart_s.png’);
mask-repeat: repeat-x;
}
img.sample2 {
mask-image: url(‘images/heart_s.png’);
mask-repeat: repeat-y;
}
img.sample3 {
mask-image: url(‘images/heart_s.png’);
mask-repeat: repeat;
}
img.sample4 {
mask-image: url(‘images/heart_s.png’);
mask-repeat: space;
}
img.sample5 {
mask-image: url(‘images/heart_s.png’);
mask-repeat: round;
}
img.sample6 {
mask-image: url(‘images/heart_s.png’);
mask-repeat: no-repeat;
}
HTMLソース
<p>
mask-repeatプロパティの指定なし<br>
<img class=”sample0″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: repeat-x; を指定<br>
<img class=”sample1″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: repeat-y; を指定<br>
<img class=”sample2″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: repeat; を指定<br>
<img class=”sample3″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: space; を指定<br>
<img class=”sample4″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: round; を指定<br>
<img class=”sample5″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: no-repeat; を指定<br>
<img class=”sample6″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
ブラウザ上の表示
mask-repeatプロパティの指定なし
mask-repeat: repeat-x; を指定
mask-repeat: repeat-y; を指定
mask-repeat: repeat; を指定
mask-repeat: space; を指定
mask-repeat: round; を指定
mask-repeat: no-repeat; を指定
■ベンダープレフィックスを付けた場合の使用例
CSSソースは外部ファイル(sample.css)に記述
img.prefix_sample0 {
-webkit-mask-image: url(‘images/heart_s.png’);
}
img.prefix_sample1 {
-webkit-mask-image: url(‘images/heart_s.png’);
-webkit-mask-repeat: repeat-x;
}
img.prefix_sample2 {
-webkit-mask-image: url(‘images/heart_s.png’);
-webkit-mask-repeat: repeat-y;
}
img.prefix_sample3 {
-webkit-mask-image: url(‘images/heart_s.png’);
-webkit-mask-repeat: repeat;
}
img.prefix_sample4 {
-webkit-mask-image: url(‘images/heart_s.png’);
-webkit-mask-repeat: space;
}
img.prefix_sample5 {
-webkit-mask-image: url(‘images/heart_s.png’);
-webkit-mask-repeat: round;
}
img.prefix_sample6 {
-webkit-mask-image: url(‘images/heart_s.png’);
-webkit-mask-repeat: no-repeat;
}
HTMLソース
<p>
mask-repeatプロパティの指定なし<br>
<img class=”prefix_sample0″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>mask-repeat: repeat-x; を指定<br>
<img class=”prefix_sample1″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: repeat-y; を指定<br>
<img class=”prefix_sample2″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: repeat; を指定<br>
<img class=”prefix_sample3″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: space; を指定<br>
<img class=”prefix_sample4″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: round; を指定<br>
<img class=”prefix_sample5″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
<p>
mask-repeat: no-repeat; を指定<br>
<img class=”prefix_sample6″ src=”https://htmqcom1.wpengine.com/wp-content/themes/twentytwentyone-child/htmq-images/uirou.png”>
</p>
ブラウザ上の表示
mask-repeatプロパティの指定なし
mask-repeat: repeat-x; を指定
mask-repeat: repeat-y; を指定
mask-repeat: repeat; を指定
mask-repeat: space; を指定
mask-repeat: round; を指定
mask-repeat: no-repeat; を指定