美文网首页
三栏式布局

三栏式布局

作者: 李丹linda | 来源:发表于2018-11-19 21:27 被阅读0次

一、浮动布局

  • 左右浮动,中间不浮动,DOM上中间要放在最后。
    <style type="text/css">
        .wrap{
            overflow: hidden;
        }
        .left{
            width: 100px;
            height: 200px;
            float: left;
            background-color: red;
        }
        .right{
            width: 100px;
            height: 200px;
            float: right;
            background-color: red;
        }
        .main{
            height: 200px;
            background-color: #000;
        }
    </style>

    <div class='wrap'>
        <div class='left'></div>
        <div class='right'></div>
        <div class='main'></div>
    </div>

二、定位布局

  • 三个盒子定位都为absolute,左的left:0;右的right:0;中间的left:100px; right : 100px; DOM正常。
    <style type="text/css">
        .wrap{
            overflow: hidden;
        }
        .wrap div{
            position: absolute;
        }
        .left{
            width: 100px;
            height: 200px;
            left: 0;
            background-color: red;
        }
        .right{
            width: 100px;
            height: 200px;
            right: 0;
            background-color: red;
        }
        .main{
            height: 200px;
            left:100px;
            right: 100px;
            background-color: #000;
        }
    </style>

三、flex布局

  • 父元素display : flex;左右定宽,中间flex : 1 ; DOM正常。
    <style type="text/css">
        .wrap{
            display: flex;
        }
        .left,.right{
            background-color: red;
            width: 100px;
            height: 200px;
        }
        .main{
            background-color: #000;
            flex: 1;
        }
    </style>

四、表格布局

  • 父元素diaplsy : table ; 子元素display : table-cell ; 左右设置宽度,DOM正常。
    <style type="text/css">
        .wrap{
            width: 100%;
            display: table;
        }
        .wrap div{
            display: table-cell;
        }
        .left{
            width: 100px;
            height: 200px;
            background-color: red;
        }
        .right{
            width: 100px;
            height: 200px;
            background-color: red;
        }
        .main{
            height: 200px;
            background-color: #000;
        }
    </style>

五、圣杯布局

  • 父元素设置左右padding,并清除浮动;
  • 子元素float : left ; position : relative;
  • 中间元素width : 100% ; 左右定宽;
  • 左元素margin-right : 100% ; left : -100px ; 右元素margin-left: -100px ; right : -100px; DOM正常。
    <style type="text/css">
        .wrap{
            padding: 0 100px 0 100px;
            overflow: hidden;
        }
        .wrap div{
            float: left;
            position: relative;
        }
        .main{
            width: 100%;
            height: 200px;
            background-color: green;
        }
        .left{
            width: 100px;
            height: 200px;
            background-color: red;
            margin-right: -100%;
            left: -100px;
        }
        .right{
            width: 100px;
            height: 200px;
            background-color: red;
            margin-left: -100px;
            right: -100px;
        }
    </style>

六、双飞翼布局

  • 父元素设置左右padding,并清除浮动;
  • 子元素float : left ; position : relative;
  • 中间元素width : 100% ; 设置左右margin;
  • 左右定宽,左元素left : -100px ; 右元素 right : -100px; DOM正常。
    <style type="text/css">
        .wrap{
            padding: 0 100px 0 100px;
            overflow: hidden;
        }
        .wrap div{
            float: left;
            position: relative;
        }
        .main{
            width: 100%;
            height: 200px;
            background-color: green;
            margin: 0 -100px;
        }
        .left{
            width: 100px;
            height: 200px;
            background-color: red;
            left: -100px;
        }
        .right{
            width: 100px;
            height: 200px;
            background-color: red;
            right: -100px;
        }
    </style>

相关文章

  • 布局

    1.实现单栏式布局 一栏布局 一栏式布局(优化) 一栏式布局(通栏) 小BUG解决办法:1. 给body或者是通栏...

  • CSS2 经典布局方案

    经典布局方式 上中下一栏式 左右两栏式 浮动+标准流式 浮动式 定位式 左右页眉页脚 左中右三栏式 双飞翼左中右三...

  • 三栏式布局

    一、浮动布局 左右浮动,中间不浮动,DOM上中间要放在最后。 二、定位布局 三个盒子定位都为absolute,左的...

  • css布局及居中

    双列布局(左右布局) 如何实现:浮动元素+普通元素 三栏式布局(左中右布局) 两侧两列固定宽度,中间列自适应宽度 ...

  • CSS常用布局方案

    上中下一栏式布局 上中下各一栏 左右两栏式布局 左侧固定,右侧自适应 float + calc:左侧浮动,右侧宽度...

  • 双栏式布局

    页面布局中经常用会遇到左侧宽度自适应,右侧固定宽度,或者左侧宽度固定,右侧自适应。总之就是一边固定宽度,一边自适应...

  • 多栏式布局

    code1code2code3code4code5code5(2)

  • 三栏式布局及引申

    查看Demo 盒模型 一张图看懂盒模型 默认情况下,一个盒子宽度会由边框长度(border),内边距(paddin...

  • 网页页面布局大全(总有一款适合你)

    3*1(三行一列)的布局方式 2列一行分栏式 4*3(4行3列)的布局方式 3*2(3行2列)的布局方式 奇妙的可...

  • CSS 布局经典问题大全

    本文主要对 CSS 布局中常见的经典问题进行简单说明,并提供相关解决方案的参考链接,涉及到三栏式布局,负 marg...

网友评论

      本文标题:三栏式布局

      本文链接:https://www.haomeiwen.com/subject/zdxzfqtx.html