# 圣杯布局、双飞翼布局
# 圣杯布局
父容器上使用padding为左右两个div空出位置,然后都是用float:left浮动,使用负的margin和相对定位调整左右两个div的位置
<div id="bd">
<div id="middle"></div>
<div id="left"></div>
<div id="right"></div>
</div>
<style>
#bd{
padding: 0 200px 0 180px;
height: 100px;
}
#middle{
float: left;
width: 100%;
height: 100px;
background: blue;
}
#left{
float: left;
width: 180px;
height: 100px;
margin-left: -100%;
background: #0c9;
position: relative;
left: -180px;
}
#right{
float: left;
width: 200px;
height: 100px;
margin-left: -200px;
background: #0c9;
position: relative;
right: -200px;
}
</style>
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
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
# 双飞翼布局
三个平级的div,在middle的div中再包一个div,使用padding空出位置,然后都是用float:left浮动,使用负的margin调整左右两个div的位置
<div id="middle">
<div id="inside"></div>
</div>
<div id="left"></div>
<div id="right"></div>
<style>
#middle{
float: left;
width: 100%;
height: 100px;
background: blue;
}
#left{
float: left;
width: 180px;
height: 100px;
margin-left: -100%;
background: #0c9;
}
#right{
float: left;
width: 200px;
height: 100px;
margin-left: -200px;
background: #0c9;
}
#inside{
margin: 0 200px 0 180px;
height: 100px;
}
</style>
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
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
# Flex实现
<div class="container">
<div class="left"></div>
<div class="main"></div>
<div class="right"></div>
</div>
<style>
.container{
display: flex;
width: 100%;
height: 100px;
}
.left{
background: green;
width: 180px;
}
.main{
background: blue;
flex:1;
}
.right{
background: red;
width: 200px;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24