-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathindex.html
330 lines (317 loc) · 10.9 KB
/
index.html
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flex 布局示例</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Flex 布局示例</h1>
<p>感谢阮一峰老师的教程<a target="_blank" href="http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html">http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html</a>
<br>本示例将教程上所有的布局都简单的实现了一遍,并保存GitHub上面
<br><a href="https://github.com/JailBreakC/flex-box-demo">https://github.com/JailBreakC/flex-box-demo</a></p>
<h2>容器的属性</h2>
<h3>1、flex-direction属性</h3>
<p>flex-direction属性决定主轴的方向(即项目的排列方向)。</p>
<p>
.box {
flex-direction: row | row-reverse | column | column-reverse;
}
</p>
<div class="box box-1">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
</div>
<h3>2、flex-wrap属性</h3>
<p>默认情况下,项目都排在一条线(又称"轴线")上。flex-wrap属性定义,如果一条轴线排不下,如何换行。</p>
<p>
.box{
flex-wrap: nowrap | wrap | wrap-reverse;
}
</p>
<p>nowrap(默认):不换行。</p>
<div class="box box-2">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
</div>
<p>wrap:换行,第一行在上方。</p>
<div class="box box-3">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
</div>
<p>wrap-reverse:换行,第一行在下方。</p>
<div class="box box-4">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
</div>
<h3>3、flex-flow</h3>
<p>flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap。</p>
<p>
.box {
flex-flow: <flex-direction> || <flex-wrap>;
}
</p>
<div class="box box-5">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
</div>
<h3>4、justify-content属性</h3>
<p>justify-content属性定义了项目在主轴上的对齐方式。</p>
<p>
.box {
justify-content: flex-start | flex-end | center | space-between | space-around;
}
</p>
<p>flex-start(默认值):左对齐</p>
<div class="box box-6">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
</div>
<p>flex-end:右对齐</p>
<div class="box box-7">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
</div>
<p>center: 居中</p>
<div class="box box-8">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
</div>
<p>space-between:两端对齐,项目之间的间隔都相等。</p>
<div class="box box-9">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
</div>
<p>space-around:每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。</p>
<div class="box box-10">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
</div>
<h3>5、align-items属性</h3>
<p>align-items属性定义项目在交叉轴上如何对齐。</p>
<p>
.box {
align-items: flex-start | flex-end | center | baseline | stretch;
}
</p>
<p>flex-start:交叉轴的起点对齐。</p>
<div class="box box-11">
<div class="box-item">1</div>
<div class="box-item item-tall">2</div>
<div class="box-item">3</div>
<div class="box-item item-tall">4</div>
</div>
<p>flex-end:交叉轴的终点对齐。</p>
<div class="box box-12">
<div class="box-item">1</div>
<div class="box-item item-tall">2</div>
<div class="box-item">3</div>
<div class="box-item item-tall">4</div>
</div>
<p>center:交叉轴的中点对齐。</p>
<div class="box box-13">
<div class="box-item">1</div>
<div class="box-item item-tall">2</div>
<div class="box-item">3</div>
<div class="box-item item-tall">4</div>
</div>
<p>baseline: 项目的第一行文字的基线对齐。</p>
<div class="box box-14 line">
<div class="box-item">1</div>
<div class="box-item item-tall">2</div>
<div class="box-item">3</div>
<div class="box-item item-tall">4</div>
</div>
<p>stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。</p>
<div class="box box-15">
<div class="box-item">1</div>
<div class="box-item item-tall">2</div>
<div class="box-item">3</div>
<div class="box-item item-tall">4</div>
</div>
<h3>6、align-content属性</h3>
<p>align-content属性定义了多根轴线(多行)的对齐方式。如果项目只有一根轴线,该属性不起作用。</p>
<p>
.box {
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
}
</p>
<p>flex-start:交叉轴的起点对齐。</p>
<div class="box box-tall box-16">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
<div class="box-item">8</div>
<div class="box-item">9</div>
</div>
<p>flex-end:与交叉轴的终点对齐。</p>
<div class="box box-tall box-17">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
<div class="box-item">8</div>
<div class="box-item">9</div>
</div>
<p>center:与交叉轴的中点对齐。</p>
<div class="box box-tall box-18">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
<div class="box-item">8</div>
<div class="box-item">9</div>
</div>
<p>space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。</p>
<div class="box box-tall box-19">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
<div class="box-item">8</div>
<div class="box-item">9</div>
</div>
<p>space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。</p>
<div class="box box-tall box-20">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
<div class="box-item">8</div>
<div class="box-item">9</div>
</div>
<p>stretch(默认值):轴线占满整个交叉轴。</p>
<div class="box box-tall box-21">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item">4</div>
<div class="box-item">5</div>
<div class="box-item">6</div>
<div class="box-item">7</div>
<div class="box-item">8</div>
<div class="box-item">9</div>
</div>
<h2>项目的属性</h2>
<h3>1、order属性</h3>
<p>order属性定义项目的排列顺序。数值越小,排列越靠前,默认为0。</p>
<p>
.item {
order: <integer>;
}
</p>
<div class="box box-22">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
<div class="box-item order">4 <div>(order:-1)</div></div>
</div>
<h3>2、flex-grow属性</h3>
<p>flex-grow属性定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大。</p>
<p>如果所有项目的flex-grow属性都为1,则它们将等分剩余空间(如果有的话)。如果一个项目的flex-grow属性为2,其他项目都为1,则前者占据的剩余空间将比其他项多一倍。</p>
<p>
.item {
flex-grow: <number>; /* default 0 */
}
</p>
<div class="box box-23">
<div class="box-item grow">1 <div>flex-grow: 1</div></div>
<div class="box-item grow grow-2">2 <div>flex-grow: 2</div></div>
<div class="box-item grow">3 <div>flex-grow: 1</div></div>
</div>
<h3>3、flex-shrink</h3>
<p>flex-shrink属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。</p>
<p>如果所有项目的flex-shrink属性都为1,当空间不足时,都将等比例缩小。如果一个项目的flex-shrink属性为0,其他项目都为1,则空间不足时,前者不缩小。<br>负值对该属性无效。</p>
<p>
.item {
flex-shrink: <number>; /* default 1 */
}
</p>
<div class="box box-24">
<div class="box-item shrink">1 <div>flex-shrink: 0</div></div>
<div class="box-item">2</div>
<div class="box-item">3</div>
</div>
<h3>4、flex-basis属性</h3>
<p>flex-basis属性定义了在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,即项目的本来大小。</p>
<p>
.item {
flex-basis: <length>; | auto; /* default auto */
}
</p>
<div class="box box-25">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
</div>
<h3>5、flex属性</h3>
<p>flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。</p>
<p>该属性有两个快捷值:auto (1 1 auto) 和 none (0 0 auto)。</p>
<p>
.item {
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
}
</p>
<h3>6、align-self属性</h3>
<p>align-self属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch。</p>
<p>
.item {
align-self: auto | flex-start | flex-end | center | baseline | stretch;
}
</p>
<div class="box box-26">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item end">3<div>flex-end</div></div>
<div class="box-item">4</div>
</div>
</body>
</html>