圣杯布局

双飞翼布局

=> 左右固定,中间自适应

圣杯布局

浮动和负margin

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
<style type='text/css'>
html,
body {
height: 100%;
overflow: hidden;
}
.container {
height: 100%;
padding: 0 200px;
}
.left,
.right {
width: 200px;
min-height: 200px;
background-color: lightblue;
}
.center {
width: 100%;
min-height: 400px;
background-color: lightsalmon;
}
.left,
.center,
.right {
float: left;
}
.left {
margin-left: -100%;
position: relative;
left: -200px;
}
.right {
margin-right: -200px;
}
</style>
</head>
<body>
<div class="container clearfix">
<div class="center"></div>
<div class="left"></div>
<div class="right"></div>
</div>
</body>

双飞翼布局

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
<style type='text/css'>
html,
body {
height: 100%;
overflow: hidden;
}

.container,
.left,
.right {
float: left;
}

.container {
width: 100%;
}

.container .center {
margin: 0 200px;
min-height: 400px;
background: lightsalmon;
}

.left,
.right {
width: 200px;
min-height: 200px;
background: lightblue;
}

.left {
margin-left: -100%;
}

.right {
margin-left: -200px;
}
</style>
</head>
<body class="clearfix">
<div class="container">
<div class="center"></div>
</div>
<div class="left"></div>
<div class="right"></div>
</body>

其他方法实现以上布局

flex

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
html,
body {
overflow: hidden;
}

.container {
display: flex;
justify-content: space-between;
height: 100%;
}

.left,
.right {
flex: 0 0 200px;
height: 200px;
background: lightblue;
}

.center {
flex: 1;
min-height: 400px;
background: lightsalmon;
}

定位

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
<style>
html,
body {
height: 100%;
overflow: hidden;
}

.container {
position: relative;
height: 100%;
}

.left,
.right {
position: absolute;
top: 0;
width: 200px;
min-height: 200px;
background: lightblue;
}

.left {
left: 0;
}

.right {
right: 0;
}

.center {
margin: 0 200px;
min-height: 400px;
background: lightsalmon;
}
</style>

calc

1
2
3
4
5
6
7
.center {
/* 兼容到IE9 */
width: calc(100% - 400px);
min-height: 400px;
background: #ffa07a;
}
......