08使用 Flexbox 布局
# 使用 Flexbox 布局
# 知识点
- 使用 Flexbox 布局安排页面空间与控件
# 官网
https://tailwindcss.com/docs/flex-direction
https://tailwindcss.com/docs/justify-content
# Flexbox讲解
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
# 实战演习
<!-- 默认布局 -->
<div class="text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 行布局 -->
<div class="flex flex-row text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 行布局(反转) -->
<div class="flex flex-row-reverse text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 列布局 -->
<div class="flex flex-col text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 列布局(反转) -->
<div class="flex flex-col-reverse text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 对齐内容 - 左对齐 -->
<div class="flex justify-start text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 对齐内容 - 右对齐 -->
<div class="flex justify-end text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 对齐内容 - 居中对齐 -->
<div class="flex justify-center text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 对齐内容 - 平均分布对齐1 -->
<div class="flex justify-between text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 对齐内容 - 平均分布对齐2 -->
<div class="flex justify-around text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 对齐内容 - 平均分布对齐3 -->
<div class="flex justify-evenly text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-10 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-10 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 水平轴对齐 - 原始 -->
<div class="text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-20 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-32 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 水平轴对齐 - 上对齐 -->
<div class="flex items-start text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-20 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-32 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 水平轴对齐 - 中对齐 -->
<div class="flex items-center text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-20 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-32 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 水平轴对齐 - 下对齐 -->
<div class="flex items-end text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-20 bg-bootstrap_success text-white m-2">2</div>
<div class="w-10 h-32 bg-bootstrap_danger text-white m-2">3</div>
</div>
<!-- 水平轴对齐 - 基准线对齐 -->
<div class="flex items-baseline text-center bg-gray-100 mt-3">
<div class="w-10 h-10 bg-bootstrap_primary text-white m-2">1</div>
<div class="w-10 h-20 bg-bootstrap_success text-white m-2 flex justify-center items-center">2</div>
<div class="w-10 h-32 bg-bootstrap_danger text-white m-2">3</div>
</div>
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
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
# 课程文件
https://github.com/komavideo/LearnTailwindCSS
# 小马视频频道
http://komavideo.com
# 小马部落
https://discord.gg/VSKw72P
编辑 (opens new window)
上次更新: 2023/08/06, 00:38:41