聖盃佈局和雙飛翼佈局解決的都是兩邊頂寬、中間自適應的三欄佈局問題,要實現中間部分優先渲染。
先上兩個demo。
聖盃佈局:
<!DOCTYPE html>
<html>
<head>
<title>聖盃佈局</title>
<meta charset="utf-8">
<style>
.header {
width: 100%;
height: 30px;
background: red;
}
.content {
overflow: hidden;
padding: 0 100px;
}
.footer {
width: 100%;
height: 30px;
background: red;
}
.middle {
position:relative;
width: 100%;
float: left;
height: 80px;
background: green;
}
.left {
position:relative;
width: 100px;
float: left;
left:-100px;
height: 80px;
margin-left: -100%;
background: yellow;
}
.right {
position:relative;
width: 100px;
float: left;
right:-100px;
height: 80px;
margin-left: -100px;
background: pink
}
</style>
</head>
<body>
<div class="header"></div>
<div class="content">
<div class="middle"></div>
<div class="left"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
</body>
</html>
雙飛翼佈局:
<!DOCTYPE html>
<html>
<head>
<title>雙飛翼佈局</title>
<meta charset="utf-8">
<style>
.header {
width: 100%;
height: 30px;
background: red;
}
.content {
overflow: hidden;
}
.footer {
width: 100%;
height: 30px;
background: red;
}
.middle {
width: 100%;
float: left;
}
.inner-middle{
height: 80px;
margin: 0 100px;
background: green;
}
.left {
width: 100px;
float: left;
height: 80px;
margin-left: -100%;
background: yellow;
}
.right {
width: 100px;
float: left;
height: 80px;
margin-left: -100px;
background: pink
}
</style>
</head>
<body>
<div class="header"></div>
<div class="content">
<div class="middle">
<div class="inner-middle"></div>
</div>
<div class="left"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
</body>
</html>
兩者的異同:
首先如開題所述,兩種佈局解決的問題是一樣的,只是實現方式有些微小的差別;
兩者都採用了向左浮動的方式,還用實現佈局的重點都是負邊距的使用;
聖盃佈局使用固定的左右padding值的限制左右欄的大小,實現中間部分的自適應,兩側部分使用了負邊距和relative控制;雙飛翼佈局則在中間欄使用了嵌套的div,在內層使用了margin來控制邊距,兩側則只使用了負邊距來保持位置;兩者相比雙飛翼佈局d增加了一個div,但少用了relative樣式。