aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/mask-repeat/index.html
blob: f052ccc58d5bbb7729f3b71802ee2a154b709858 (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
184
185
186
---
title: mask-repeat
slug: Web/CSS/mask-repeat
translation_of: Web/CSS/mask-repeat
---
<div>{{CSSRef}}{{SeeCompatTable}}</div>

<p><a href="/zh-CN/docs/Web/CSS">CSS</a><strong><code>mask-repeat</code></strong> 属性定义了遮罩图片是否重复显示多个副本,以及如何重复。一个遮罩图片可以水平重复、垂直重复或双向重复,也可以不重复。</p>

<pre class="brush: css no-line-numbers">/* 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;
</pre>

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

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

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

<p>One or more <code>&lt;repeat-style&gt;</code> values, separated by commas.</p>

<h3 id="取值">取值</h3>

<dl>
 <dt><code>&lt;repeat-style&gt;</code></dt>
 <dd>单值语法可将两个值简写为一个:</dd>
 <dd>
 <table class="standard-table">
  <tbody>
   <tr>
    <td><strong>单值</strong></td>
    <td><strong>与之等效的双值</strong></td>
   </tr>
   <tr>
    <td><code>repeat-x</code></td>
    <td><code>repeat no-repeat</code></td>
   </tr>
   <tr>
    <td><code>repeat-y</code></td>
    <td><code>no-repeat repeat</code></td>
   </tr>
   <tr>
    <td><code>repeat</code></td>
    <td><code>repeat repeat</code></td>
   </tr>
   <tr>
    <td><code>space</code></td>
    <td><code>space space</code></td>
   </tr>
   <tr>
    <td><code>round</code></td>
    <td><code>round round</code></td>
   </tr>
   <tr>
    <td><code>no-repeat</code></td>
    <td><code>no-repeat no-repeat</code></td>
   </tr>
  </tbody>
 </table>
 在双值语法中,第一个值代表了水平方向的行为,第二个值代表了垂直方向的行为。下面是每个选项的用法解释:</dd>
 <dd>
 <table class="standard-table">
  <tbody>
   <tr>
    <td><code>repeat</code></td>
    <td>The 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.</td>
   </tr>
   <tr>
    <td><code>space</code></td>
    <td>The 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 {{cssxref("mask-position")}} property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using <code>space</code> is when there isn't enough room to display one image.</td>
   </tr>
   <tr>
    <td><code>round</code></td>
    <td>As 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.</td>
   </tr>
   <tr>
    <td><code>no-repeat</code></td>
    <td>The 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 {{cssxref("mask-position")}} CSS property.</td>
   </tr>
  </tbody>
 </table>
 </dd>
</dl>

<h3 id="正式语法">正式语法</h3>

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

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

<h3 id="单值">单值</h3>

<h4 id="CSS">CSS</h4>

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

<div class="hidden">
<h4 id="HTML">HTML</h4>

<pre class="brush: html">&lt;div id="masked"&gt;
&lt;/div&gt;
&lt;select id="repetition"&gt;
  &lt;option value="repeat-x"&gt;repeat-x&lt;/option&gt;
  &lt;option value="repeat-y"&gt;repeat-y&lt;/option&gt;
  &lt;option value="repeat" selected&gt;repeat&lt;/option&gt;
  &lt;option value="space"&gt;space&lt;/option&gt;
  &lt;option value="round"&gt;round&lt;/option&gt;
  &lt;option value="no-repeat"&gt;no-repeat&lt;/option&gt;
&lt;/select&gt;
</pre>

<h4 id="JavaScript_Content">JavaScript Content</h4>

<pre class="brush: js">var repetition = document.getElementById("repetition");
repetition.addEventListener("change", function (evt) {
  document.getElementById("masked").style.maskRepeat = evt.target.value;
});
</pre>
</div>

<p>{{EmbedLiveSample("Single_value", "290px", "290px")}}</p>

<h3 id="使用多个遮罩图片">使用多个遮罩图片</h3>

<p>You can specify a different <code>&lt;repeat-style&gt;</code> for each mask image, separated by commas:</p>

<pre class="brush: css">.examplethree {
  mask-image: url('mask1.png'), url('mask2.png');
  mask-repeat: repeat-x, repeat-y;
}
</pre>

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

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS Masks", "#the-mask-repeat", "mask-repeat")}}</td>
   <td>{{Spec2("CSS Masks")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

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



<p>{{Compat("css.properties.mask-repeat")}}</p>