中间固定 左右自适应 css写法

本文介绍了一种使用HTML和CSS实现三栏布局的方法,其中中间栏固定宽度并居中显示,左右两栏分别占据剩余空间。通过绝对定位和margin属性,实现了响应式设计,适用于不同屏幕尺寸。

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

html:
<div class="container">
    <div class="left">
         <div class="left-container">

         </div>
    </div>
    <div class="center">

    </div>
    <div class="right">
        <div class="right-container">

        </div>
    </div>
</div>

css:

<style>
    .container{
        position: absolute;
        top:0;
        bottom: 0;
        left:0;
        right:0;
    }
    .center{
        position: absolute;
        width: 200px;
        height: 100%;
        left:50%;
        margin-left: -100px;
        z-index: 100;
        background-color: red;
    }
    .left{
        position: absolute;
        top:0;
        bottom: 0;
        left:0;
        width: 50%;
    }
    .right{
        position: absolute;
        top:0;
        bottom: 0;
        right:0;
        width: 50%;
    }
    .left-container{
        margin-right: 100px;
        background-color: #00a854;
        height: 100%;
    }
    .right-container{
        margin-left: 100px;
        background-color: #ca900e;
        height: 100%;
    }
</style>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

跃焱邵隼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值