圣杯布局与双飞翼布局

为了实现左右两侧固定,中间内容宽度可调,发明的布局方式

在这里插入图片描述

  • 圣杯布局
    左中右在一个容器中,左右通过覆盖padding内容完成
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        header,footer {
            background-color: skyblue;height: 50px;text-align: center;line-height: 50px;
        }
        .center,.left,.right {
            float: left;
        }
     
        .left {
            width: 100px;
            left: -100px;
            margin-left: -100%;
            position: relative;
            background-color: antiquewhite;
        }

        .right {
            width: 100px;
            background-color: antiquewhite;
            right: -100px;
            margin-left: -100px;
            position: relative;
        }

        .center {
            width: 100%;
            height: 100px;
            background-color: aquamarine;
        }
        .wrap{
            padding: 0 100px;
        }

        .clearfix::after{
            content: "";
            display: block;
            clear: both;
        }
    </style>
    
</head>
<body>
    <header>头部</header>
    <div class="clearfix wrap">
        <div class="center">主区域</div>
        <div class="left">左区域</div>
        <div class="right">右区域</div>
    </div>
    <footer>底部</footer>
</body>
</html>
  • 双飞翼布局
    中间自己一个容器,左右分别通过覆盖margin显示
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        header,footer {
            background-color: skyblue;height: 50px;text-align: center;line-height: 50px;
        }
        .center,.left,.right {
            float: left;
        }

        .wrap {
            width: 100%;
            float: left;
        }
        .left {
            width: 100px;
            margin-left: -100%;
            background-color: antiquewhite;
        }

        .right {
            width: 100px;
            background-color: antiquewhite;
            margin-left: -100px;
        }

        .center {
            margin: 0 100px;
            height: 50px;  
            background-color: aquamarine;
        }

        .clearfix{
            clear: both;
        }
    </style>
    
</head>
<body>
    <header>头部</header>
    <div class="wrap">
        <div class="center">主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域主区域</div>
    </div>
    <div class="left">左区域</div>
    <div class="right">右区域</div>
    <footer class="clearfix">底部</footer>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值