如果高度確定,怎么進(jìn)行三欄布局,左右300px,中間自適應(yīng)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Layout</title>
<style media="screen">
html *{
padding: 0;
margin: 0;
}
.layout article div{
min-height: 100px;
}
</style>
</head>
<body>
<!--浮動(dòng)布局 -->
<section class="layout float">
<style media="screen">
.layout.float .left{
float:left;
width:300px;
background: red;
}
.layout.float .center{
background: yellow;
}
.layout.float .right{
float:right;
width:300px;
background: blue;
}
</style>
<h1>三欄布局</h1>
<article class="left-right-center">
<div class="left"></div>
<div class="right"></div>
<div class="center">
<h2>浮動(dòng)解決方案</h2>
1.這是三欄布局的浮動(dòng)解決方案;
2.這是三欄布局的浮動(dòng)解決方案;
3.這是三欄布局的浮動(dòng)解決方案;
4.這是三欄布局的浮動(dòng)解決方案;
5.這是三欄布局的浮動(dòng)解決方案;
6.這是三欄布局的浮動(dòng)解決方案;
</div>
</article>
</section>
<!-- 絕對(duì)布局 -->
<section class="layout absolute">
<style>
.layout.absolute .left-center-right>div{
position: absolute;
}
.layout.absolute .left{
left:0;
width: 300px;
background: red;
}
.layout.absolute .center{
left: 300px;
right: 300px;
background: yellow;
}
.layout.absolute .right{
right:0;
width: 300px;
background: blue;
}
</style>
<h1>三欄布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>絕對(duì)定位解決方案</h2>
1.這是三欄布局的浮動(dòng)解決方案;
2.這是三欄布局的浮動(dòng)解決方案;
3.這是三欄布局的浮動(dòng)解決方案;
4.這是三欄布局的浮動(dòng)解決方案;
5.這是三欄布局的浮動(dòng)解決方案;
6.這是三欄布局的浮動(dòng)解決方案;
</div>
<div class="right"></div>
</article>
</section>
<!-- flexbox布局 -->
<section class="layout flexbox">
<style>
.layout.flexbox{
margin-top: 110px;
}
.layout.flexbox .left-center-right{
display: flex;
}
.layout.flexbox .left{
width: 300px;
background: red;
}
.layout.flexbox .center{
flex:1;
background: yellow;
}
.layout.flexbox .right{
width: 300px;
background: blue;
}
</style>
<h1>三欄布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>flexbox解決方案</h2>
1.這是三欄布局的浮動(dòng)解決方案;
2.這是三欄布局的浮動(dòng)解決方案;
3.這是三欄布局的浮動(dòng)解決方案;
4.這是三欄布局的浮動(dòng)解決方案;
5.這是三欄布局的浮動(dòng)解決方案;
6.這是三欄布局的浮動(dòng)解決方案;
</div>
<div class="right"></div>
</article>
</section>
<!-- 表格布局 -->
<section class="layout table">
<style>
.layout.table .left-center-right{
width:100%;
height: 100px;
display: table;
}
.layout.table .left-center-right>div{
display: table-cell;
}
.layout.table .left{
width: 300px;
background: red;
}
.layout.table .center{
background: yellow;
}
.layout.table .right{
width: 300px;
background: blue;
}
</style>
<h1>三欄布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>表格布局解決方案</h2>
1.這是三欄布局的浮動(dòng)解決方案;
2.這是三欄布局的浮動(dòng)解決方案;
3.這是三欄布局的浮動(dòng)解決方案;
4.這是三欄布局的浮動(dòng)解決方案;
5.這是三欄布局的浮動(dòng)解決方案;
6.這是三欄布局的浮動(dòng)解決方案;
</div>
<div class="right"></div>
</article>
</section>
<!-- 網(wǎng)格布局 -->
<section class="layout grid">
<style>
.layout.grid .left-center-right{
width:100%;
display: grid;
grid-template-rows: 100px;
grid-template-columns: 300px auto 300px;
}
.layout.grid .left{
width: 300px;
background: red;
}
.layout.grid .center{
background: yellow;
}
.layout.grid .right{
background: blue;
}
</style>
<h1>三欄布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>網(wǎng)格布局解決方案</h2>
1.這是三欄布局的浮動(dòng)解決方案;
2.這是三欄布局的浮動(dòng)解決方案;
3.這是三欄布局的浮動(dòng)解決方案;
4.這是三欄布局的浮動(dòng)解決方案;
5.這是三欄布局的浮動(dòng)解決方案;
6.這是三欄布局的浮動(dòng)解決方案;
</div>
<div class="right"></div>
</article>
</section>
</body>
</html>
這是比較普遍的五種方案。
優(yōu)缺點(diǎn):
1.float布局:把清除浮動(dòng)和周圍元素的關(guān)系處理好就兼容性比較好。缺點(diǎn)是脫離文檔流容易出問題。
2.position布局: 快捷,容易實(shí)現(xiàn)。但是脫離文檔流導(dǎo)致子元素也脫離文檔流,可使用性比較差。
3.flexbox布局: 比較完美的一種方案,為了解決以上兩種方案的不足出現(xiàn)的。移動(dòng)端基本都是這種布局方案。因?yàn)槭荂SS3的屬性,所以對(duì)舊版本的瀏覽器不友好。
4.表格布局: 有時(shí)候麻煩,操作繁瑣,高度改變之后其他單元格也跟著改變。但是兼容性非常好。
5.網(wǎng)格布局: 參考柵格布局。可以解決很多復(fù)雜的事情但是代碼量要簡(jiǎn)化的多。
改變前提,高度不可知
高度不確定的情況下float,position跟網(wǎng)格布局會(huì)出現(xiàn)問題。所以flexbox跟表格布局會(huì)是高度未知情況下的好的解決方案