aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/flex-wrap/index.html
blob: 7fc3f1b342d92eda66b8bc63e61ebb55463a37d4 (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
187
188
189
190
191
192
193
---
title: flex-wrap
slug: Web/CSS/flex-wrap
tags:
  - CSS3
  - Default value
  - Flex
  - flex-wrap
translation_of: Web/CSS/flex-wrap
---
<p>{{ CSSRef("CSS Flexible Boxes") }}</p>

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

<p><a href="/zh-CN/docs/CSS" title="CSS">CSS</a> <strong><code>flex-wrap</code></strong> 指定 flex 元素单行显示还是多行显示 。如果允许换行,这个属性允许你控制行的堆叠方向。</p>

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

<p>参考 <a href="/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes" title="使用 CSS 弹性盒子">使用 CSS 弹性盒子</a> 查看更多的属性和信息</p>

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

<pre class="brush:css">flex-wrap: nowrap;  /* Default value */
flex-wrap: wrap;
flex-wrap: wrap-reverse;

/* Global values */
flex-wrap: inherit;
flex-wrap: initial;
flex-wrap: unset;
</pre>

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

<p>下面这些值是可以接受的:</p>

<dl>
 <dt><code>nowrap</code></dt>
 <dd>flex 的元素被摆放到到一行,这可能导致溢出 flex 容器。 <strong>cross-start</strong>  会根据 {{cssxref("flex-direction")}} 的值 相当于 <strong>start</strong><strong>before</strong></dd>
 <dt><code>wrap</code></dt>
 <dd>flex 元素 被打断到多个行中。<strong>cross-start</strong> 会根据 {{cssxref("flex-direction")}} 的值选择等于<strong>start</strong><strong>before</strong><strong>cross-end</strong> 为确定的 <strong>cross-start</strong> 的另一端。</dd>
 <dt><code>wrap-reverse</code></dt>
 <dd>和 wrap 的行为一样,但是 <strong>cross-start</strong><strong>cross-end </strong>互换。</dd>
 <dt>
 <h3 id="语法格式">语法格式</h3>
 </dt>
</dl>

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

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

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

<pre><code>&lt;h4&gt;This is an example for flex-wrap:wrap &lt;/h4&gt;
&lt;div class="content"&gt;
  &lt;div class="red"&gt;1&lt;/div&gt;
  &lt;div class="green"&gt;2&lt;/div&gt;
  &lt;div class="blue"&gt;3&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;This is an example for flex-wrap:nowrap &lt;/h4&gt;
&lt;div class="content1"&gt;
  &lt;div class="red"&gt;1&lt;/div&gt;
  &lt;div class="green"&gt;2&lt;/div&gt;
  &lt;div class="blue"&gt;3&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;This is an example for flex-wrap:wrap-reverse &lt;/h4&gt;
&lt;div class="content2"&gt;
  &lt;div class="red"&gt;1&lt;/div&gt;
  &lt;div class="green"&gt;2&lt;/div&gt;
  &lt;div class="blue"&gt;3&lt;/div&gt;
&lt;/div&gt;</code></pre>

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

<pre><code>/* Common Styles */
.content,
.content1,
.content2 {
    color: #fff;
    font: 100 24px/100px sans-serif;
    height: 150px;
    text-align: center;
}

.content div,
.content1 div,
.content2 div {
    height: 50%;
    width: 50%;
}
.red {
    background: orangered;
}
.green {
    background: yellowgreen;
}
.blue {
    background: steelblue;
}

/* Flexbox Styles */
.content {
    display: flex;
    flex-wrap: wrap;
}
.content1 {
    display: flex;
    flex-wrap: nowrap;
}
.content2 {
    display: flex;
    flex-wrap: wrap-reverse;
}</code></pre>

<h3 id="结果">结果</h3>

<p>{{ EmbedLiveSample('Examples', '700px', '700px', '', 'Web/CSS/flex-wrap') }}</p>

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

<table class="standard-table">
 <thead>
  <tr>
   <th>规范</th>
   <th>状态</th>
   <th>备注</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('CSS3 Flexbox', '#flex-wrap-property', 'flex-wrap') }}</td>
   <td>{{ Spec2('CSS3 Flexbox') }}</td>
   <td>                    </td>
  </tr>
 </tbody>
</table>

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

<table>
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Firefox (Gecko)</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>28.0</td>
   <td>29.0</td>
   <td>12.0</td>
   <td>11.0<sup>[1]</sup></td>
   <td>17.0</td>
   <td>9.0</td>
  </tr>
 </tbody>
</table>

<table>
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Firefox for Android (Gecko)</th>
   <th>Android</th>
   <th>Edge</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>52.0</td>
   <td>4.4</td>
   <td>12.0</td>
   <td>11.0</td>
   <td>12.1</td>
   <td>9.2</td>
  </tr>
 </tbody>
</table>

<h2 id="参考">参考</h2>

<ul>
 <li><a href="/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes" title="使用 CSS 弹性盒子">使用 CSS 弹性盒<br></a></li>
</ul>