mask-repeat - CSS(层叠样式表) 编辑

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

CSSmask-repeat 属性定义了遮罩图片是否重复显示多个副本,以及如何重复。一个遮罩图片可以水平重复、垂直重复或双向重复,也可以不重复。

/* One-value syntax */
mask-repeat: repeat-x;
mask-repeat: repeat-y;
mask-repeat: repeat;
mask-repeat: space;
mask-repeat: round;
mask-repeat: no-repeat;

/* Two-value syntax: horizontal | vertical */
mask-repeat: repeat space;
mask-repeat: repeat repeat;
mask-repeat: round space;
mask-repeat: no-repeat round;

/* Multiple values */
mask-repeat: space round, no-repeat;
mask-repeat: round repeat, space, repeat-x;

/* Global values */
mask-repeat: inherit;
mask-repeat: initial;
mask-repeat: unset;

默认情况下,重复的图片会被剪切为图片的大小,但他们可以自行缩放适应(使用 round),或者从一端到另一端均匀分布(使用 space)。

初始值no-repeat
适用元素all elements; In SVG, it applies to container elements excluding the defs element and all graphics elements
是否是继承属性
计算值Consists of two keywords, one per dimension
Animation typediscrete

语法

One or more <repeat-style> values, separated by commas.

取值

<repeat-style>
单值语法可将两个值简写为一个:
单值与之等效的双值
repeat-xrepeat no-repeat
repeat-yno-repeat repeat
repeatrepeat repeat
spacespace space
roundround round
no-repeatno-repeat no-repeat
在双值语法中,第一个值代表了水平方向的行为,第二个值代表了垂直方向的行为。下面是每个选项的用法解释:
repeatThe image is repeated as much as needed to cover the whole mask painting area. The last image will be clipped if it doesn't fit.
spaceThe image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The mask-position property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using space is when there isn't enough room to display one image.
roundAs the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px.
no-repeatThe image is not repeated (and hence the mask painting area will not necessarily be entirely covered). The position of the non-repeated mask image is defined by the mask-position CSS property.

正式语法

<repeat-style>#

where
<repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}

例子

单值

CSS

#masked {
  width: 250px;
  height: 250px;
  background: blue linear-gradient(red, blue);
  mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg);
  mask-repeat: repeat; /* 可在实时示例 live sample 中修改 */
  margin-bottom: 10px;
}

HTML

<div id="masked">
</div>
<select id="repetition">
  <option value="repeat-x">repeat-x</option>
  <option value="repeat-y">repeat-y</option>
  <option value="repeat" selected>repeat</option>
  <option value="space">space</option>
  <option value="round">round</option>
  <option value="no-repeat">no-repeat</option>
</select>

JavaScript Content

var repetition = document.getElementById("repetition");
repetition.addEventListener("change", function (evt) {
  document.getElementById("masked").style.maskRepeat = evt.target.value;
});

使用多个遮罩图片

You can specify a different <repeat-style> for each mask image, separated by commas:

.examplethree {
  mask-image: url('mask1.png'), url('mask2.png');
  mask-repeat: repeat-x, repeat-y;
}

Each image is matched with the corresponding repeat style, from first specified to last.

规范

规范状态备注
CSS Masking Module Level 1
mask-repeat
Candidate RecommendationInitial definition

浏览器兼容性

BCD tables only load in the browser

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:102 次

字数:10055

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文