此方法的原理說將左右兩側進行定位,讓其脫離文檔流。 中心區域天然流動到它們下面,再爲其設置margin值bash
此方法頁面元素結構能夠順序能夠隨意變更, 注意top值須要進行處理,否則可能會出現對不齊現象佈局
HTMLflex
<div id='container'>
<div class='left'>左側</div>
<div class='center'>中間</div>
<div class='right'>右側</div>
</div>
複製代碼
CSSui
#container {
position: relative;
}
.left, .right{
position: absolute;
top: 0;
width: 200px;
min-height: 500px;
background-color: red;
}
.left {
left: 0;
}
.right {
right: 0;
}
.center {
margin: 0px 210px;
min-height: 500px;
background-color: yellow;
}
複製代碼
此方法的原理說將左右兩側進行float 浮動讓其脫離文檔流,中心部分處於正常文檔流,再爲其設置margin值spa
此方法必定要將center中間部分放到最後,當窗口特別小時右側會被擠下來code
HTML文檔
<div id='container'>
<div class='left'>左側</div>
<div class='right'>右側</div>
<div class='center'>中間</div>
</div>
複製代碼
CSSstring
#container {
position: relative;
}
.left, .right {
width: 200px;
min-height: 500px;
background-color: red;
}
.left {
float: left;
}
.right {
float: right;
}
.center {
min-height: 500px;
margin: 0px 210px;
background-color: yellow;
}
複製代碼
此方法最多見,三者相互關聯,最穩健。 首先須要將中間部分放再最前面,外面用一層容器包裹。外層容器讓其佔滿整個屏幕100%, 左中右三者都float: left。 將center左右margin設置爲兩邊容器的寬度加上邊距,將left左側margin-left設置爲-100%,讓其出如今最左側,將right右側margin-right設置爲-200px,讓其出如今最右側。it
HTMLio
<div id='container'>
<div class='center_wrap'>
<div class='center'>中間</div>
</div>
<div class='left'>左側</div>
<div class='right'>右側</div>
</div>
複製代碼
CSS
#container {
position: relative;
}
.center_wrap, .left, .right{
float: left;
min-height: 500px;
}
.center_wrap {
width: 100%;
}
.center_wrap .center{
min-height: 500px;
margin: 0px 210px;
background-color: yellow;
}
.left, .right {
width: 200px;
background-color: red;
}
.left {
margin-left: -100%;
}
.right {
margin-left: -200px;
}
複製代碼
HTML
<div id='container'>
<div class='left'>左側</div>
<div class='center'>中間</div>
<div class='right'>右側</div>
</div>
複製代碼
CSS
#container {
width: 100%;
display: flex;
}
.left, .right {
width: 200px;
background-color: red;
min-height: 500px;
}
.center {
flex: 1;
min-height: 500px;
margin: 0 10px;
background-color: yellow;
}
複製代碼