時間:2023-09-26 10:18:01 | 來源:網(wǎng)站運營
時間:2023-09-26 10:18:01 來源:網(wǎng)站運營
利用div+css實現(xiàn)幾種經(jīng)典布局的詳解,樣式以及代碼?。?h2 data-first-child>一、左右兩側(cè),左側(cè)固定寬度200px,右側(cè)自適應(yīng)占滿效果<div class="container"> <div class="left"></div> <div class="right"></div> </div>
css代碼*{ margin: 0px; padding: 0px; } .container{ height: 500px; background: yellow; } .left{ float: left; width: 200px; height: 100%; background: red; } .right{ margin-left: 200px; background: green; height: 100%; }
這個實現(xiàn)起來比較的簡單,左側(cè)的div給浮動,右側(cè)的divmargin-left使其從左側(cè)div右側(cè)開始展現(xiàn),加背景顏色方便觀察。<div class="container"> <div class="left"></div> <div class="right"></div> <div class="center"></div> </div>
css代碼 *{ margin:0px; padding: 0px; } .container{ background: yellow; height: 500px; } .left{ background: red; float: left; width: 200px; height: 100%; } .center{ /*第一種用浮動,加上左右外邊距,不用絕對定位 這里我推薦把html中的right寫在center的前面,如果按順序?qū)懙脑挄裷ight擠到下面,感興趣的可以自己試試 */ /*margin: 0 200px;*/ /*第二種用浮動加絕對定位*/ /*position: absolute; left: 200px; right: 200px;*/ background: grey; height: 500px; } .right{ background: green; float: right; width: 200px; height: 100%; }
<div class="container"> <div class="top"></div> <div class="center"></div> <div class="bottom"></div> </div>
css代碼*{ margin:0px; padding: 0px; } .container{ background: yellow; width: 100%; } .top{ background: red; width: 100%; height: 200px; position: absolute; top: 0; } .center{ width: 100%; background: grey; position: absolute; top: 200px; bottom: 200px; } .bottom{ width: 100%; background: green; height: 200px; position: absolute; bottom: 0;
這里用到了絕對定位,把上面的和下面的分別設(shè)置top:0,bottom:0 固定在上下兩端,中間的距離上下200px即可<div class="container"> <div class="content"></div> <div class="footer"></div> </div>
css代碼 *{ margin: 0px; padding: 0px; } html{ height: 100%; } body{ min-height: 100%; position: relative; } .content{ width: 100%; background:red; padding-bottom: 200px; } .footer{ width: 100%; height: 200px; background: green; position: absolute; bottom: 0; }
固定footer在底部和把foorter往下擠著走都比較容易實現(xiàn),但是合到一起,就不好弄了吧,其實也不難,更改content的高度,就可以看到效果了關(guān)鍵詞:樣式,布局,實現(xiàn),經(jīng)典,利用
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。