--- title: mask-image slug: Web/CSS/mask-image translation_of: Web/CSS/mask-image ---
mask-image
CSS属性用于设置元素上遮罩层的图像。
{{cssinfo}}
/* Keyword value */ mask-image: none; /* <mask-source> value */ mask-image: url(masks.svg#mask1); /* <image< values */ mask-image: linear-gradient(rgba(0, 0, 0, 1.0), transparent); mask-image: image(url(mask.png), skyblue); /* Multiple values */ mask-image: image(url(mask.png), skyblue), linear-gradient(rgba(0, 0, 0, 1.0), transparent); /* Global values */ mask-image: inherit; mask-image: initial; mask-image: unset;
none
<mask-source>
<mask>
或CSS图像的url#masked { width: 100px; height: 100px; background-color: #8cffa0; mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg); -webkit-mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg); }
<div id="masked"></div>
{{EmbedLiveSample('例子', '100px', '100px')}}
Specification | Status | Comment |
---|---|---|
{{SpecName("CSS Masks", "#the-mask-image", "mask-image")}} | {{Spec2("CSS Masks")}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Edge | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 1.0{{property_prefix("-webkit")}}[1] | {{CompatNo}}[2] | {{CompatNo}} | {{CompatUnknown}} | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} | 4.0{{property_prefix("-webkit")}}[3] |
Multiple mask images | 1.0{{property_prefix("-webkit")}} | {{CompatNo}}[2] | {{CompatNo}} | {{CompatUnknown}} | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} | 4.0{{property_prefix("-webkit")}} |
SVG masks | 8.0 | {{CompatNo}}[2] | {{CompatNo}} | {{CompatUnknown}} | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} | 4.0{{property_prefix("-webkit")}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 2.1{{property_prefix("-webkit")}}[4] | {{CompatNo}}[2] | {{CompatUnknown}} | {{CompatNo}} | 3.2{{property_prefix("-webkit")}}[5] |
Multiple mask images | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} | {{CompatNo}}[2] | {{CompatUnknown}} | {{CompatNo}} | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} |
SVG masks | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} | {{CompatNo}}[2] | {{CompatUnknown}} | {{CompatNo}} | {{CompatVersionUnknown}}{{property_prefix("-webkit")}} |
[1] Implemented in version 8.0, Chrome initially only supported the -webkit
prefixed versions of gradients as values. Later, support for the unprefixed versions was added.
[2] This feature is not implemented yet. It is only available in Nightly and Dev Edition. See {{bug("1251161")}}.
[3] Implemented in version 4.0, Safari initially only supported the -webkit
prefixed versions of gradients as values.
[4] Android initially only supported the -webkit
prefixed versions of gradients as values.
[5] iOS Safari initially only supported the -webkit
prefixed versions of gradients as values.