实现三栏布局,中间自适应

float布局 + margin

<!-- float布局,middle部分放最后(最后加载) -->
    <div class="wrap">
        <div class="left">左侧</div>
        <div class="right">右侧</div>
        <div class="middle">中间</div>
    </div>
/* float布局 设置左右浮动,中间设置对应margin */
    .left {
        width: 200px;
        height: 200px;
        float: left;
        background: coral;
    }
    .right {
        width: 200px;
        height: 200px;
        float: right;
        background: lightblue;
    }
    .middle {
        margin: 0 220px;
        height: 200px;
        background: #555;
    }

position定位+margin

<!-- position定位,正常加载 -->
<div class="wrap">
        <div class="left">左侧</div>
        <div class="middle">中间</div>
        <div class="right">右侧</div>
    </div>
/* 
        position定位,父盒子设置relative相对定位,
        子盒子设置absolute绝对定位,左侧盒子设置top、left偏移量0;
        右侧设置right、top偏移0
        中间设置对应margin
     */

    .wrap {
        position: relative;
    }
    .left {
        position: absolute;
        top: 0;
        left: 0;
        width: 100px;
        height: 200px;
        background: coral;
    }

    .right {
        position: absolute;
        top: 0;
        right: 0;
        width: 100px;
        height: 200px;
        background: lightblue;
    }

    .middle {
        height: 200px;
        margin: 0 110px;
        background: #555;
    }

flex布局

<!-- flex 布局,左中右 -->
    <div class="wrap">
        <div class="left">左侧</div>
        <div class="middle">中间</div>
        <div class="right">右侧</div>
    </div>
/* flex布局,给父元素设置flex,中间width设置100%*/
    .wrap {
        display: flex;
        justify-content: space-between;
    }
    .left {
        width: 200px;
        height: 100px;
        background: coral;
    }
    .right {
        width: 120px;
        height: 100px;
        background: lightblue;
    }
    .middle {
        width: 100%;
        height: 100px;
        margin: 0 20px;
        background: #555;
    }

grid网格布局

<div class="wrap">
        <div class="left">左侧</div>
        <div class="middle">中间</div>
        <div class="right">右侧</div>
    </div>
/* grid布局,grid-template-columns属性设置列宽 */
    .wrap {
        display: grid;
        /* 设置列宽 */
        grid-template-columns: 200px auto 200px;
    }
    .left {
        height: 100px;
        background: coral;
    }
    .right {
        height: 100px;
        background: lightblue;
    }

    .middle {
        height: 100px;
        background: #555;
        margin:0  20px;
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值