三栏布局的实现(左右固定宽,中间自适应)

第一种使用float布局
<style>
    html{
        height: 100%;
    }
    body{
        height: 100%;
    }
    .box{
        width: 100%;
        height: 100%;
    }
    .left{
        width: 200px;
        height: 100%;
        background-color: aqua;
        float: left;
    }
    .right{
        width: 200px;
        height: 100%;
        background-color: blue;
        float: right;
    }
    .middle{
        background-color: black;
        width: calc(100% - 400px);
        float: left;
        height: 100%;
    }
</style>
<div class="box">
    <div class="left">left</div>
    <div class="middle">middle</div>
    <div class="right">right</div>
</div>
第二种使用float加margin
<style>
    html{
        height: 100%;
    }
    body{
        height: 100%;
    }
    .box{
        width: 100%;
        height: 100%;
    }
    .left{
        width: 200px;
        height: 100%;
        background-color: aqua;
        float: left;
    }
    .right{
        width: 200px;
        height: 100%;
        background-color: blue;
        margin-top: -100vh;
        float: right;
    }
    .middle{
        margin-left: 200px;
        background-color: black;
        width: calc(100% - 400px);
        height: 100%;
    }
</style>
<div class="box">
    <div class="left">left</div>
    <div class="middle">middle</div>
    <div class="right">right</div>
</div>
第三种:flex布局
 html{
        height: 100%;
    }
    body{
        height: 100%;
    }
    .box{
        width: 100%;
        height: 100%;
        display: flex;
    }
    .left{
        width: 200px;
        height: 100%;
        background-color: aqua;
    }
    .right{
        width: 200px;
        height: 100%;
        background-color: blue;
    }
    .middle{
        background-color: black;
        flex:1;
        height: 100%;
    }
</style>
<div class="box">
    <div class="left">left</div>
    <div class="middle">middle</div>
    <div class="right">right</div>
</div>

第四种:定位实现

<style>
    html{
        height: 100%;
    }
    body{
        height: 100%;
    }
    .box{
        width: 100%;
        height: 100%;
        position: relative;
    }
    .left{
        width: 200px;
        height: 100%;
        background-color: aqua;
        position: absolute;
        left: 0;
    }
    .right{
        width: 200px;
        height: 100%;
        background-color: blue;
        position: absolute;
        right: 0;
    }
    .middle{
        background-color: black;
        width: calc(100% - 400px);
        height: 100%;
        position: absolute;
        left: 200px;
    }
</style>
<div class="box">
    <div class="left">left</div>
    <div class="middle">middle</div>
    <div class="right">right</div>
</div>

效果都是:
在这里插入图片描述

第五种:双飞翼布局
<style>
    body,
    html {
        height: 100%;
    }

    .container {
        height: 100%;
    }

    .center {
        width: 100%;
        height: 100%;
        background-color: burlywood;
        float: left;
    }

    .middle {
        width: 100%;
        height: 100%;
        margin: 0 200px;
    }

    .left {
        width: 200px;
        height: 100%;
        float: left;
        background-color: cadetblue;
    }

    .right {
        width: 200px;
        height: 100%;
        float: left;
        background-color: coral;
    }
</style>

<body>
    <div class="container">
        <div class="center">
            <div class="middle">middle</div>
        </div>
        <div class="left">left</div>
        <div class="right">right</div>
    </div>
第六种:圣杯布局
<style>
    html,
    body {
        height: 100%;
    }

    .container {
        width: 100%;
        height: 100%;
    }
    .middle {
        width: 100%;
        height: 100%;
        background-color: cornflowerblue;
        padding: 0 200px;
        box-sizing: border-box;
        float: left;
    }

    .left {
        width: 200px;
        height: 100%;
        background-color: cyan;
        margin-left: -100%;
        float: left;
    }

    .right {
        width: 200px;
        height: 100%;
        background-color: darkcyan;
        margin-left: -200px;
        float: left;
    }
</style>
<div class="container">
    <div class="middle">middle</div>
    <div class="left">left</div>
    <div class="right">right</div>
</div>
双飞翼布局和圣杯布局很类似,不同的地方在于left和right块的位置相对于谁而言。这两种方法跟前面几种不同的还有加载顺序,这两种是浏览器先加载中间的再加载两边的,所以看需求吧。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值