--- title: mask slug: Web/CSS/mask translation_of: Web/CSS/mask ---
CSS 属性 mask
允许使用者通过遮罩或者裁切特定区域的图片的方式来隐藏一个元素的部分或者全部可见区域。
/* Keyword values */ mask: none; /* Image values */ mask: url(mask.png); /* 使用位图来做遮罩 */ mask: url(masks.svg#star); /* 使用 SVG 图形中的形状来做遮罩 */ /* Combined values */ mask: url(masks.svg#star) luminance; /* Element within SVG graphic used as luminance mask */ mask: url(masks.svg#star) 40px 20px; /* 使用 SVG 图形中的形状来做遮罩并设定它的位置:离上边缘40px,离左边缘20px */ mask: url(masks.svg#star) 0 0/50px 50px; /* 使用 SVG 图形中的形状来做遮罩并设定它的位置和大小:长宽都是50px */ mask: url(masks.svg#star) repeat-x; /* Element within SVG graphic used as horizontally repeated mask */ mask: url(masks.svg#star) stroke-box; /* Element within SVG graphic used as mask extending to the box enclosed by the stroke */ mask: url(masks.svg#star) exclude; /* Element within SVG graphic used as mask and combined with background using non-overlapping parts */ /* Global values */ mask: inherit; mask: initial; mask: unset;
mask的简写会将 {{cssxref("mask-border")}} 设为初始值。使用 mask
的简写优于使用其他简写或者各自属性的设置来覆盖。这能保证 mask-border
也会重新设置为新的效果样式。
{{cssinfo}}
<mask-reference>
<masking-mode>
<position>
<bg-size>
<repeat-style>
<geometry-box>
<geometry-box> | no-clip
<compositing-operator>
{{csssyntax}}
.target { mask: url(#c1) luminance; } .anothertarget { mask: url(resources.svg#c1) 50px 30px/10px 10px repeat-x exclude; }
规范 | 状态 | 备注 |
---|---|---|
{{SpecName("CSS Masks", "#the-mask", 'mask')}} | {{Spec2("CSS Masks")}} | Extends its usage to HTML elements. Extends its syntax by making it a shorthand for the new mask-* properties defined in that specification. |
{{SpecName('SVG1.1', 'masking.html#MaskProperty', 'mask')}} | {{Spec2('SVG1.1')}} | Initial definition |
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.
{{Compat("css.properties.mask")}}