三列布局(左右宽度固定,中间自适应)的五种解决方案

1.float浮动布局

html:

    <section class="layout float">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center"></div>
    </section>

css

         <style>
            *{
                margin: 0;
                padding: 0;
            }
            .layout.float>div{
               height: 100px;
            }
            .layout.float .left{
                float: left;
                width: 300px;
                background: red;
            }
            .layout.float .right{
                float: right;
                width: 300px;
                background: blue;
            }
            .layout.float .center{
                margin-left: 300px;
                margin-right: 300px;
                background: yellow;
            }
        </style>

2.定位布局

html:

    <section class="layout absolute">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </section>

css:

         <style>
            *{
                margin:0;
                padding:0;
            }
            .layout.absolute>div{
                height: 100px;
                position:absolute;
            }
            .layout.absolute .left{
                left:0;
                width: 300px;
                background: red;
            }
            .layout.absolute .center{
                left: 300px;
                right: 300px;
                background: green;
            }
            .layout.absolute .right{
                right: 0;
                width: 300px;
                background: blue;
            }
        </style>

3.flex布局

html:

    <section class="layout flex">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </section>

css:

         <style>
            *{
                margin:0;
                padding:0;
            }
            .layout.flex{
                display: flex;
            }
            .layout.flex>div{
                height: 100px;
            }
            .layout.flex .left{
                width: 300px;
                background: red;
            }
            .layout.flex .center{
                flex: 1;
                background: green;
            }
            .layout.flex .right{
                width: 300px;
                background: blue;
            }
        </style>

4.表格布局

html:

    <section class="layout table">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </section>

css:

         <style>
            *{
                margin:0;
                padding:0;
            }
            .layout.table{
                display: table;
                width: 100%;
            }
            .layout.table>div{
                display: table-cell;
                height: 100px;
            }
            .layout.table .left{
                width: 300px;
                background: red;
            }
            .layout.table .center{
                background: yellow;
            }
            .layout.table .right{
                width: 300px;
                background: blue;
            }
        </style>

5.网格布局

html:

    <section class="layout grid">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </section>

css:

         <style>
            *{
                margin:0;
                padding:0;
            }
            .layout.grid{
                width: 100%;
                display:grid;
                grid-template-rows: 100px;
                grid-template-columns: 300px auto 300px;
            }
            .layout.grid .left{
                background: red;
            }
            .layout.grid .center{
                background: yellow;
            }
            .layout.grid .right{
                background: blue;
            }
        </style>
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值