圣杯布局和双飞翼
-
两者的功能相同,都是为了实现一个两侧宽度固定,中间宽度自适应的三栏布局。
-
圣杯布局
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>
<body>
<div id="header">head</div>
<div id="container">
<div id="center" class="column">center</div>
<div id="left" class="column">left</div>
<div id="right" class="column">right</div>
</div>
<div id="footer">footer</div>
</body>
</html>
#container {
padding-left: 200px;
padding-right: 150px;
}
#container .column{
float:left;
}
#center{
background:blue;
width:100%;
}
#left{
background:orange;
margin-left:-100%;
width:200px;
position:relative;
right:200px;
}
#right{
background:red;
width:150px;
margin-right:-150px;
}
#header{
background:grey;
}
#footer{
background:grey;
clear:both;
}
html{
min-width:550px;
}
- 双飞翼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>
<body>
<div id="header">head</div>
<div id="container">
<div id="center" class="column">center</div>
</div>
<div id="left" class="column">left</div>
<div id="right" class="column">right</div>
<div id="footer">footer</div>
</body>
</html>
#container {
width:100%
}
.column{
float:left;
}
#center{
background:yellow;
margin-left:200px;
margin-right:150px;
}
#left{
background:blue;
width:200px;
margin-left:-100%;
}
#right{
background:red;
width:150px;
margin-right:-150px;
}
#header{
background:grey;
}
#footer{
background:grey;
clear:both;
}
- flex
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>
<body>
<div id="header">head</div>
<div id="container">
<div id="left" class="column">left</div>
<div id="center" class="column">center</div>
<div id="right" class="column">right</div>
</div>
<div id="footer">footer</div>
</body>
</html>
#container {
display:flex;
}
#center{
flex-grow:1;
background-color:yellow;
}
#left{
background:blue;
flex-basis:200px;
}
#right{
background:red;
flex-basis:200px;
}
#header{
background:grey;
}
#footer{
background:grey;
}
- 总结:
flex真的方便