題目:假設(shè)高度已知,請(qǐng)寫出三欄布局,其中左欄、右欄寬度各為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-center-right>div{
}
.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>
1.每個(gè)方案的優(yōu)缺點(diǎn)
2 .假如把高度去掉,那個(gè)方案不再適用了
3.兼容性到業(yè)務(wù)中那個(gè)最實(shí)用
浮動(dòng):清除浮動(dòng) 與其周邊的元素的關(guān)系處理好。兼容性好;
絕對(duì)定位:快捷;缺點(diǎn):導(dǎo)致子元素脫離文檔流,可使用性差;
flex: 是為了解決上述兩個(gè)問題而解決的。相對(duì)是比較完美的;
table布局:兼容性比較好。缺點(diǎn):一個(gè)高度被撐開,其他的也會(huì)受影響;
網(wǎng)格布局:新的技術(shù)布局。
float 增加高度解決辦法添加bfc.
小結(jié)
1.語義化掌握到位
2.頁面布局理解深刻
3.CSS基礎(chǔ)知識(shí)扎實(shí)
4.思維靈活且積極向上
5.代碼書寫規(guī)范