10. 左右宽度固定300px,中间自适应,5种布局方案

本文介绍两种实现三栏布局的方法:浮动布局与绝对定位布局。浮动布局通过设置左右两栏浮动,中间栏自然填充;绝对定位布局则直接为各栏设置精确的位置属性。这两种方法适用于不同场景,帮助开发者灵活应对网页布局需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、浮动解决方案

<section class="layout float">
    <style>
        .layout.float .left{
            float: left;
            width: 300px;
            background: red;
        }
        .layout.float .right{
            float: right;
            width: 300px;
            background: blue;
        }
        .layout.float .center{
            background: yellow;
        }
    </style>
    <article class="left-right-center">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center">
            <h1>浮动解决方案</h1>
            1.这是三栏布局中间部分
            2.这是三栏布局中间部分
        </div>
    </article>
</section>

 

2、 绝对定位absolute解决方案

<section class="layout absolute">
    <style>
        .layout.absolute .left-right-center > div{
            position: absolute;
        }
        .layout.absolute .left{
            left: 0;
            width: 300px;
            background: red;
        }
        .layout.absolute .center{
            left: 300px;
            right: 300px;
            background: yellow;
        }
        .layout.absolute .right{
            right: 0;
            width: 300px;
            background: blue;
        }
    </style>
    <article class="left-right-center">
        <div class="left"></div>
        <div class="center">
            <h1>绝对定位解决方案</h1>
            1.这是三栏布局绝对定位中间部分
            2.这是三栏布局绝对定位中间部分
        </div>
        <div class="right"></div>
    </article>
</section>

 

3、

转载于:https://www.cnblogs.com/zouxinping/p/9341010.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值