CSS等高佈局

作一些後臺項目,和一下帶側邊欄項目的時候登高佈局很經常使用,總結了下有幾種css

1.margin-bottom方法佈局

這裏直接介紹我認爲的最佳的側邊欄/分欄高度自動相等方法。核心的CSS代碼以下(數值不固定):ui

margin-bottom:-3000px; padding-bottom:3000px;

再配合父標籤的overflow:hidden屬性便可實現高度自動相等的效果。spa

舉個簡單的實例吧,以下CSS及HTML代碼:code

#content{overflow:hidden;}
.left{width:200px; margin-bottom:-3000px; padding-bottom:3000px; background:#cad5eb; float:left;}
.right{width:400px; margin-bottom:-3000px; padding-bottom:3000px; background:#f0f3f9; float:right;}
.center{margin:0 410px 0 210px; background:#ffe6b8; height:600px;}
<div id="content">
    <div class="left">左邊,無高度屬性,自適應於最高一欄的高度</div>
    <div class="right">右邊,無高度屬性,自適應於最高一欄的高度</div>
    <div class="center">中間,高度600像素,左右兩欄的高度與之自適應</div>
</div>

後續再慢慢總結比較實用的幾種參考:http://www.w3cplus.com/css/creaet-equal-height-columns   http://www.w3cplus.com/css/two-cloumn-width-one-fixed-width-one-fluid-width
相關文章
相關標籤/搜索