aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/mask-image/index.html
blob: cb3e1ce5d369e8b9a7a84c8b3f66f806d2d92b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
title: mask-image
slug: Web/CSS/mask-image
translation_of: Web/CSS/mask-image
---
<div>{{CSSRef}}{{SeeCompatTable}}</div>

<h2 id="概要">概要</h2>

<p><strong><code>mask-image</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a>属性用于设置元素上遮罩层的图像。</p>

<p>{{cssinfo}}</p>

<h2 id="语法">语法</h2>

<pre class="brush:css">/* Keyword value */
mask-image: none;

/* &lt;mask-source&gt; value */
mask-image: url(masks.svg#mask1);

/* &lt;image&lt; 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;
</pre>

<h3 id="Values">Values</h3>

<dl>
 <dt><code>none</code></dt>
 <dd>默认值,透明的黑色图像层,也就是没有遮罩层。</dd>
 <dt><code>&lt;mask-source&gt;</code></dt>
 <dd><code>&lt;mask&gt;</code>或CSS图像的url</dd>
 <dd>{{cssxref("&lt;image&gt;")}}</dd>
 <dd>图片作为遮罩层</dd>
</dl>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="例子">例子</h2>

<h3 id="CSS">CSS</h3>

<pre class="brush: css; highlight[5]">#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);
}
</pre>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;div id="masked"&gt;&lt;/div&gt;
</pre>

<p>{{EmbedLiveSample('例子', '100px', '100px')}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS Masks", "#the-mask-image", "mask-image")}}</td>
   <td>{{Spec2("CSS Masks")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Edge</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0{{property_prefix("-webkit")}}<sup>[1]</sup></td>
   <td>{{CompatNo}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
   <td>4.0{{property_prefix("-webkit")}}<sup>[3]</sup></td>
  </tr>
  <tr>
   <td>Multiple mask images</td>
   <td>1.0{{property_prefix("-webkit")}}</td>
   <td>{{CompatNo}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
   <td>4.0{{property_prefix("-webkit")}}</td>
  </tr>
  <tr>
   <td>SVG masks</td>
   <td>8.0</td>
   <td>{{CompatNo}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
   <td>4.0{{property_prefix("-webkit")}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>2.1{{property_prefix("-webkit")}}<sup>[4]</sup></td>
   <td>{{CompatNo}}<sup>[2]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>3.2{{property_prefix("-webkit")}}<sup>[5]</sup></td>
  </tr>
  <tr>
   <td>Multiple mask images</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
   <td>{{CompatNo}}<sup>[2]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
  </tr>
  <tr>
   <td>SVG masks</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
   <td>{{CompatNo}}<sup>[2]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Implemented in version 8.0, Chrome initially only supported the <code>-webkit</code> prefixed versions of gradients as values. Later, support for the unprefixed versions was added.</p>

<p>[2] This feature is not implemented yet. It is only available in Nightly and Dev Edition. See {{bug("1251161")}}.</p>

<p>[3] Implemented in version 4.0, Safari initially only supported the <code>-webkit</code> prefixed versions of gradients as values.</p>

<p>[4] Android initially only supported the <code>-webkit</code> prefixed versions of gradients as values.</p>

<p>[5] iOS Safari initially only supported the <code>-webkit</code> prefixed versions of gradients as values.</p>