若是高度肯定,怎麼進行三欄佈局,左右300px,中間自適應html
<!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>
<!--浮動佈局 -->
<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>浮動解決方案</h2>
1.這是三欄佈局的浮動解決方案;
2.這是三欄佈局的浮動解決方案;
3.這是三欄佈局的浮動解決方案;
4.這是三欄佈局的浮動解決方案;
5.這是三欄佈局的浮動解決方案;
6.這是三欄佈局的浮動解決方案;
</div>
</article>
</section>
<!-- 絕對佈局 -->
<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>絕對定位解決方案</h2>
1.這是三欄佈局的浮動解決方案;
2.這是三欄佈局的浮動解決方案;
3.這是三欄佈局的浮動解決方案;
4.這是三欄佈局的浮動解決方案;
5.這是三欄佈局的浮動解決方案;
6.這是三欄佈局的浮動解決方案;
</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.這是三欄佈局的浮動解決方案;
2.這是三欄佈局的浮動解決方案;
3.這是三欄佈局的浮動解決方案;
4.這是三欄佈局的浮動解決方案;
5.這是三欄佈局的浮動解決方案;
6.這是三欄佈局的浮動解決方案;
</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.這是三欄佈局的浮動解決方案;
2.這是三欄佈局的浮動解決方案;
3.這是三欄佈局的浮動解決方案;
4.這是三欄佈局的浮動解決方案;
5.這是三欄佈局的浮動解決方案;
6.這是三欄佈局的浮動解決方案;
</div>
<div class="right"></div>
</article>
</section>
<!-- 網格佈局 -->
<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>網格佈局解決方案</h2>
1.這是三欄佈局的浮動解決方案;
2.這是三欄佈局的浮動解決方案;
3.這是三欄佈局的浮動解決方案;
4.這是三欄佈局的浮動解決方案;
5.這是三欄佈局的浮動解決方案;
6.這是三欄佈局的浮動解決方案;
</div>
<div class="right"></div>
</article>
</section>
</body>
</html>
複製代碼
高度不肯定的狀況下float,position跟網格佈局會出現問題。因此flexbox跟表格佈局會是高度未知狀況下的好的解決方案瀏覽器