div是left-right-centercss
效果圖
html
css
css3
* { margin: 0; padding: 0; } .layout .content div{ min-height: 100px; } .layout .content .left{ float: left; width: 300px; background: pink; } .layout .content .right{ float: right; width: 300px; background: yellow; } .layout .content .center { background: red; }
html
佈局
<section class="layout"> <article class="content"> <div class="left">左邊內容</div> <div class="right">右邊內容</div> <div class="center">浮動佈局中間內容</div> </article> </section>
缺點: 定位的元素脫離了文檔流,意味着子元素也要脫離文檔流,因此這種方式的可以使用性比較差flex
效果圖flexbox
css
3d
.layout-absolute .absolute-content { position: relative; } .layout-absolute .absolute-content div { min-height: 100px; } .layout-absolute .absolute-content .left { position: absolute; left: 0; width: 300px; background: pink; } .layout-absolute .absolute-content .right { position: absolute; right: 0; width: 300px; background: yellow; } .layout-absolute .absolute-content .center { position:absolute; left: 300px; right: 300px; background: red; }
html
code
<section class="layout-absolute"> <article class="absolute-content"> <div class="left">定位左邊內容</div> <div class="center">定位佈局中間內容</div> <div class="right">定位右邊內容</div> </article> </section>
缺點:兼容性比較差(css3的屬性),不兼容IE8及如下htm
效果圖blog
css
.flexbox-content { display: flex; width: 100%; } .flexbox-content div { min-height: 100px; } .flexbox-content .left { width: 300px; background: pink; } .flexbox-content .right { width: 300px; background: yellow; } .flexbox-content .center { flex: 1; background: red; }
html
<section class="flexbox"> <article class="flexbox-content"> <div class="left">固定定位左邊內容</div> <div class="center">固定定位中間內容</div> <div class="right">固定定位右邊內容</div> </article> </section>
缺點:操做繁瑣,當三欄中其中某一欄高度超出時,其餘兩欄的高度也會自動跟着調整(不符合某些場景)
效果圖
css
.table-content { display: table; width: 100%; } .table-content div{ display: table-cell; height: 100px; } .table-content .left { width: 300px; background: pink; } .table-content .center { background: red; } .table-content .right { width: 300px; background: yellow; }
html
<section class="flexbox"> <article class="flexbox-content"> <div class="left">固定定位左邊內容</div> <div class="center">固定定位中間內容</div> <div class="right">固定定位右邊內容</div> </article> </section>
css
.grid-content { display: grid; width: 100%; grid-template-rows: 100px; grid-template-columns: 300px auto 300px; } .grid-content .left { background: pink; } .grid-content .center { background: red; } .grid-content .right { background: yellow; }
html
<section class="grid"> <article class="grid-content"> <div class="left">網格佈局左邊內容</div> <div class="center">網格佈局中間內容</div> <div class="right">網格佈局右邊內容</div> </article> </section>