三欄布局將主頁(yè)分成3部分左中右,左右定寬,中間自適應(yīng)
1.浮動(dòng)實(shí)現(xiàn)
兼容好,易實(shí)現(xiàn)
左右浮動(dòng),再寫(xiě)中間,需要去浮動(dòng)
<style>
.left {
width: 100px;
height: 100px;
background: lightcoral;
float: left;
}
.right {
width: 100px;
height: 100px;
background: lightskyblue;
float: right;
}
.center {
margin: 0 100px;
height: 100px;
background: mediumpurple;
}
</style>
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
2.定位實(shí)現(xiàn)
左右分別定位兩側(cè),中間左右margin 和左右寬度一致
脫離文檔流,順序正常
<style>
*{
margin:0;
padding: 0;
}
.left {
width: 100px;
height: 100px;
background: lightcoral;
position: absolute;
left: 0;
right: 0;
}
.right {
width: 100px;
height: 100px;
background: lightskyblue;
position: absolute;
right: 0;
top: 0;
}
.center {
height: 100px;
background: mediumorchid;
margin: 0 100px;
}
</style>
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
3.flex實(shí)現(xiàn)
<style>
*{
margin:0;
padding: 0;
}
.container {
display: flex;
}
.left {
width: 100px;
height: 100px;
background: lightskyblue;
}
.right {
width: 100px;
height: 100px;
background: orangered;
}
.center {
height: 100px;
background: orchid;
flex: 1;
}
</style>
<div class="container">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>