-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy paththree-column.html
166 lines (166 loc) · 5.08 KB
/
three-column.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html * {
padding: 0;
margin: 0;
}
.layout {
margin-top: 10px;
}
.layout article div {
min-height: 100px;
}
</style>
</head>
<body>
<!-- 方法一 通过浮动,当center块的内容太长,就会使得center部分溢出,所以在center下加了overflow:hidden -->
<section class="layout float">
<style>
.layout.float .left {
width: 300px;
float: left;
background: yellow;
}
.layout.float .right {
width: 300px;
float: right;
background: blue;
}
.layout.float .center {
background: red;
overflow: hidden;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="right"></div>
<div class="center">
<h2>我的float布局解决方案哈哈哈啊哈哈哈哈哈</h2>
</div>
</article>
</section>
<!-- 第二种方式 左,中,右,设置绝对定位,左边left,0,右边right:0, 中间 left right, 等于左右的宽 -->
<section class="layout absoluted">
<style>
.layout.absoluted .left-center-right>div {
position: absolute; /* 相对的是 html */
}
.layout.absoluted .left {
left: 0px;
width: 300px;
background: yellow;
}
.layout.absoluted .center {
left: 300px;
right: 300px;
background: red;
}
.layout.absoluted .right {
right: 0px;
width: 300px;
background: blue;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>我是absoluted布局解决方案</h2>
</div>
<div class="right"></div>
</article>
</section>
<!-- 第三种方式:通过 display: flex,center 部分flex-grow 占据剩余部分 -->
<section class="layout flexb">
<style>
.layout.flexb {
margin-top: 120px;
}
.layout.flexb .left-center-right {
display: flex;
}
.layout.flexb .left {
width: 300px;
background: yellow;
}
.layout.flexb .center {
flex-grow: 1;
background: red;
}
.layout.flexb .right {
width: 300px;
background: blue;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>我是flex解决方案</h2>
</div>
<div class="right"></div>
</article>
</section>
<!-- 第四种方式: 左,中,右 table-cell 父级 table -->
<section class="layout table">
<style>
.layout.table .left-center-right {
display: table;
width: 100%;
height: 100px;
}
.layout.table .left-center-right>div {
display: table-cell;
}
.layout.table .left {
width: 300px;
background: yellow;
}
.layout.table .center {
background: red;
}
.layout.table .right {
width: 300px;
background: blue;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>我是Table解决方案</h2>
</div>
<div class="right"></div>
</article>
</section>
<!--第五种 grid -->
<section class="layout grid">
<style>
.layout.grid .left-center-right {
display: grid;
width: 100%;
grid-template-rows: 100px;
grid-template-columns: 300px auto 300px;
}
.layout.grid .left {
background: yellow;
}
.layout.grid .center {
background: red;
}
.layout.grid .right {
background: blue;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>我是grid解决方案</h2>
</div>
<div class="right"></div>
</article>
</section>
</body>
</html>