My Little World

flex-drection属性使用

在display:flex基础上使用flex-direction,可用于多子模块布局

flex-direction可以为四个值

row:水平并行排列在左侧

row-reverse:水平并行排列在右侧,顺序与书写顺序相反,最前的在最右边

column:垂直排列在上方,相当于display:block状态下模块默认布局

column-reverse:垂直排列在下方,顺序与书写顺序相反,最前的在最下边

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
<!doctype html>
<html>
<head>
<style>
#main1
{
width:200px;
height: 300px;
border:1px solid black;
display: flex;
flex-direction:row;
}
#main2
{
width:200px;
height: 300px;
border:1px solid black;
display: flex;
flex-direction:row-reverse;
}
#main3
{
width:200px;
height: 300px;
border:1px solid black;
display: flex;
flex-direction:column;
}
#main4
{
width:200px;
height: 300px;
border:1px solid black;
display: flex;
flex-direction:column-reverse;
}
</style>
</head>
<body>
<h4>This is an example for flex-direction:row(default)</h4>
<div id="main1">
<div style="background-color:red;">RED</div>
<div style="background-color:lightblue;">BLUE</div>
<div style="background-color:lightgreen;">GREEN</div>
</div>
<h4>This is an example for flex-direction:row-reverse</h4>
<div id="main2">
<div style="background-color:red;">RED</div>
<div style="background-color:lightblue;">BLUE</div>
<div style="background-color:lightgreen;">GREEN</div>
</div>
<h4>This is an example for flex-direction:column</h4>
<div id="main3">
<div style="background-color:red;">RED</div>
<div style="background-color:lightblue;">BLUE</div>
<div style="background-color:lightgreen;">GREEN</div>
</div>
<h4>This is an example for flex-direction:column-reverse</h4>
<div id="main4">
<div style="background-color:red;">RED</div>
<div style="background-color:lightblue;">BLUE</div>
<div style="background-color:lightgreen;">GREEN</div>
</div>
</body>
</html>