圣杯布局and双飞翼布局

作用:两者的功能相同,都是为了实现一个两侧宽度固定,中间宽度自适应的三栏布局。(中间先加载渲染)
区别:圣杯布局主要是利用父容器的左右内边距以及左右列的相对定位。(float+position)
双飞翼布局是把主列嵌套在父容器中,再用主列的左右外边距进行调整。(float)

圣杯布局
代码:

  <style>
        header,
        footer {
            height: 50px;
            background-color: pink;
        }

        .wrapper {
            padding: 0 200px;
        }

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

        .left {
            float: left;
            width: 200px;
            margin-left: -100%;
            position: relative;
            left: -200px;
        }

        .right {
            float: left;
            width: 200px;
            margin-left: -200px;
            position: relative;
            right: -200px;
        }

        .clearfix::after {
            content: '';
            display: block;
            clear: both;
        }
    </style>
</head>

<body>
    <header>头部</header>
    <div class="clearfix wrapper">
        <div class="center">主区域</div>
        <div class="left">左区域</div>
        <div class="right">右区域</div>
    </div>
    <footer>底部</footer>
</body>

结果截图
在这里插入图片描述

双飞翼布局
代码:

    <style>
        header,
        footer {
            height: 50px;
            background-color: pink;
        }

        .wrapper {
            float: left;
            width: 100%;
        }

        .center {
            margin: 0 200px;
            background-color: red;
            height: 50px;
        }

        .left {
            float: left;
            width: 200px;
            margin-left: -100%;
        }

        .right {
            float: left;
            width: 200px;
            margin-left: -200px;
        }

        footer {
            clear: both;
        }
    </style>
</head>

<body>
    <header></header>
    <div class="wrapper">
        <div class="center">中间区域</div>
    </div>
    <div class="left">左区域</div>
    <div class="right">右区域</div>
    <footer></footer>
</body>

运行结果
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值