CSS实现三栏布局 发表于 2018-07-22 | 阅读次数: | 字数统计: 466字 | 阅读时长 ≈ 3分钟 | 阅读次数 该博客主要介绍的是通过css实现三栏布局的几种方案 通过浮动实现三栏布局 12345678910111213141516171819202122232425262728<section> <style type="text/css"> .float-layout div{ height: 100px; } .float-layout .left{ float: left; width: 200px; background-color: red; } .float-layout .right{ float: right; width: 200px; background-color: yellow; } .float-layout .center{ margin:0 200px; background-color: blue; } </style> <article class="float-layout"> <div class="left">1</div> <div class="right">3</div> <div class="center">float实现三栏布局解决方案</div> </article> </section> 通过定位实现三栏布局 12345678910111213141516171819202122232425262728293031323334<section> <style type="text/css"> .position-layout div{ height: 100px; margin-top: 20px;//是为了和上面的有一定的间距 } .position-layout .left{ position: absolute; top: 100px; left: 0px; width: 200px; background-color: red; } .position-layout .center{ margin: 0 200px; margin-top: 20px; background-color: blue; } .position-layout .right{ position: absolute; top: 100px; right:0px; width: 200px; background-color: yellow; } </style> <article class="position-layout"> <div class="left">1</div> <div class="center">position实现三栏布局解决方案</div> <div class="right">3</div> </article> </section> 通过flex实现三栏布局 123456789101112131415161718192021222324252627<section> <style type="text/css"> .flex-layout{ display: flex; height: 100px; margin-top: 20px; } .flex-layout .left{ width: 200px; background-color: red; } .flex-layout .center{ flex: 1; background-color: blue; } .flex-layout .right{ width: 200px; background-color: yellow; } </style> <article class="flex-layout"> <div class="left">1</div> <div class="center">flex实现三栏布局解决方案</div> <div class="right">3</div> </article> </section> 通过table实现三栏布局 123456789101112131415161718192021222324252627282930<section> <style type="text/css"> .table-layout{ display: table; width: 100%; margin-top: 20px; } .table-layout>div{ display: table-cell; height: 100px; } .table-layout .left{ width: 200px; background-color: red; } .table-layout .right{ width: 200px; background-color: yellow; } .table-layout .center{ background-color: blue; } </style> <article class="table-layout"> <div class="left">1</div> <div class="center">table实现三栏布局解决方案</div> <div class="right">3</div> </article> </section> 通过grid实现三栏布局 123456789101112131415161718192021222324<section> <style type="text/css"> .grid-layout{ display: grid; grid-template-columns: 200px auto 200px; height: 100px; margin-top: 20px; } .grid-layout .left{ background-color: red; } .grid-layout .center{ background-color: blue; } .grid-layout .right{ background-color: yellow; } </style> <article class="grid-layout"> <div class="left">1</div> <div class="center">grid实现三栏布局解决方案</div> <div class="right">3</div> </article> </section> 实例图片如下: 本文作者: Kian_ 本文链接: https://tianxiaosi.github.io/2018/07/23/CSS实现三栏布局/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!