css三栏布局方法

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

css三栏布局方法

         .wrap > div {height: 100px; text-align: center; line-height: 100px; }

1.float

使用float注意清除浮动
清除浮动有三种

  1. 父盒子使用overflow:hidden,但是超出区域会被隐藏
  2. 浮动的盒子下方加一个标签 clear:both
  3. 伪元素清除浮动 父元素添加class
 .clear:after{
            content: "";
            height: 0;
            line-height: 0;
            display: block;
            visibility: hidden;
            clear: both;
        }
        .float .left {
            width: 200px;
            float: left;
            background-color: pink;
        }
        .float .center {
            background-color: green;
        }
        .float .right {
            width: 200px;
            float: right;
            background-color: orange;
        }
 <div class="float wrap">
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>
</div>

2.flex

flex 的设置宽度和中间自适应具体是哪个属性
flex :flex-grow flex-shrink flex-basis
放大 缩小 固定值
0 1 auto

.flex {
            display: flex;
            flex-direction: row;
            flex-wrap: nowrap;
            justify-content: space-between;
            align-items: center;
        }
        .flex .left {
            width: 200px;
            background-color: lightblue;
        }
        .flex .center {
            flex: 1;
            background-color: lightsalmon;
        }
        .flex .right {
            width: 200px;
            background-color: lawngreen;
        }
        <div class="flex wrap">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
</div>

3.table

 .table {
            display: table;
            width: 100%;
        }
        .table > div {
            display: table-cell;
        }
        .table .left {
            width: 200px;
            background-color: lavenderblush;

        }
        .table .center {
            background-color: lightseagreen;
        }
        .table .right {
            width: 200px;
            background-color: lightcoral;
        }
        <div class="table wrap">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值