-
Notifications
You must be signed in to change notification settings - Fork 23
/
圣杯布局.html
68 lines (66 loc) · 1.8 KB
/
圣杯布局.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>圣杯布局</title>
<style type="text/css">
#header, #footer{
height: 30px;
background: #ccc;
}
#left{
background: red;
height: 100px;
}
#center{
background: green;
}
#right{
background: yellow;
height: 100px;
}
</style>
<style type="text/css">
body {
min-width: 550px; /* 2x LC width + RC width */
}
#container {
padding-left: 200px; /* LC width */
padding-right: 150px; /* RC width */
}
#container .column {
position: relative;
float: left;
}
#center {
width: 100%;
}
#left {
width: 200px; /* LC width */
right: 200px; /* LC width */
margin-left: -100%;
}
#right {
width: 150px; /* RC width */
margin-right: -150px; /* RC width */
}
#footer {
clear: both;
}
/*** IE6 Fix ***/
* html #left {
left: 150px; /* RC width */
}
</style>
</head>
<body>
<div id="header">头部</div>
<div id="container">
<div id="center" class="column">圣杯布局指两边顶宽,中间自适应的三栏布局,中间栏要在放在文档流前面以优先渲染。参考: <a href="http://alistapart.com/article/holygrail"> 圣杯布局原理</a>。其流程为:1)设置container的左右padding,用于预留左右边栏的空间。 2)给所有元素设置定位和浮动,用于设置左右两栏偏移; 3)给左侧边栏设置right,让其移动位置。设置负边距100%(#center的宽度),让其跑到上面; 4)给右边栏设置负边距使其跑到上面</div>
<div id="left" class="column">左侧边栏,固定宽度</div>
<div id="right" class="column">右侧边栏,固定宽度</div>
</div>
<div id="footer">尾部</div>
</body>
</html>