圣杯布局与双飞翼布局

圣杯布局

html结构

1
2
3
4
5
6
7
8
<div class="header">头部</div>
<div class="main clearfix">
<div class="center">中间自适应</div>
<!-- 因为相对来说,center中为主要内容,所以写前边,这样也有利于SEO -->
<div class="left">左列定宽</div>
<div class="right">右列定宽</div>
</div>
<div class="footer">底部</div>

CSS

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
.header {
height: 40px;
background: lightblue;
}
.footer {
height: 100px;
background: lightcoral;
}

.clearfix::after {
content: "";
display: block;
clear: both;
}

.main {
margin-left: 200px;
margin-right: 300px;
/* padding: 0 300px 0 200px; */
}

.center {
width: 100%;
height: 500px;
background: lightgray;
float: left;
}
.left {
width: 200px;
height: 500px;
background: lightpink;
float: left;
margin-left: -100%;
position: relative;
left: -200px;
}
.right {
width: 300px;
height: 500px;
background: lightgreen;
float: left;
margin-left: -300px;
position: relative;
right: -300px;
}


点击查看 demo

双飞翼布局

html

1
2
3
4
5
6
7
8
9
<div class="header">头部</div>
<div class="main clearfix">
<div class="center">
<div class="inner">中间自适应</div>
</div>
<div class="left">左列定宽</div>
<div class="right">右列定宽</div>
</div>
<div class="footer">底部</div>

CSS

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
.header {
height: 40px;
background: lightblue;
}
.footer {
height: 100px;
background: lightcoral;
}

.clearfix::after {
content: "";
display: block;
clear: both;
}

.center {
width: 100%;
height: 500px;
background: lightgray;
float: left;
}
.left {
width: 200px;
height: 500px;
background: lightpink;
float: left;
margin-left: -100%;
}
.right {
width: 300px;
height: 500px;
background: lightgreen;
float: left;
margin-left: -300px;
}

.inner {
height: 100%;
background-color: green;
margin: 0 300px 0 200px;
}


点击查看 demo

参考


理解各种css布局(一)
http://example.com/2022/09/13/layout-study/
作者
toshiba
发布于
2022年9月13日
许可协议