双飞翼布局实现

是什么?

双飞翼布局是一种常见的网页布局方式,具有两个侧边栏和一个中间内容区域。

与圣杯布局不同的是,双飞翼布局将三个部分放在同一层级的div中,而且左右两个侧边栏的宽度可以不固定,适应更加灵活。

实现方式

方式一:【 flex实现双飞翼布局

1、给中部父盒子设置宽度100%设置display:flex;,

2、给左侧和右侧盒子设置固定的宽度,高度固定值

3、中间的盒子设置flex-grow: 1;,宽度不设置,高度固定值

4、头部和底部设置宽度100%,高度固定值

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,body{
            margin:0;
            padding:0;
        }
        .flex {
            width: 100%;
            display: flex;
            text-align: center;
        }

        .left {
            height: 400px;
            width: 200px;
            text-align: center;
            background-color: blue;
        }

        .right {
            height: 400px;
            width: 200px;
            text-align: center;
            background-color: blue;
        }

        .center {
            flex-grow: 1;
            height: 400px;
            text-align: center;
            background-color: aqua;
        }

        header {
            width: 100%;
            height: 100px;
            text-align: center;
            background-color: pink;
        }

        footer {
            width: 100%;
            height: 100px;
            text-align: center;
            background-color: pink;
        }
    </style>
</head>

<body>
    <header>头部</header>
    <div class="flex">
        <div class="left">左侧盒子</div>
        <div class="center">中部盒子</div>
        <div class="right">右侧盒子</div>
    </div>
    <footer>底部</footer>
</body>

</html>

方式二:【calc实现双飞翼布局】

1、左右两个盒子设置固定的宽度,高度固定值

2、中间盒子的宽度设置为width: calc(100% - “左侧盒子宽度” - “右侧盒子宽度”);注意减号两边的空格,高度固定值

3、三个盒子设置float: left;排在同一行显示,则可以实现双飞翼布局

4、头部和底部设置宽度100%,高度固定值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .left {
            height: 400px;
            width: 200px;
            text-align: center;
            background-color: blue;
            float: left;
        }
 
        .right {
            height: 400px;
            width: 200px;
            text-align: center;
            background-color: blue;
            float: left;
        }
 
        .center {
            height: 400px;
            width: calc(100% - 200px - 200px);
            background-color: aqua;
            text-align: center;
            float: left;
 
        }
 
        header {
            width: 100%;
            height: 100px;
            text-align: center;
            background-color: pink;
        }
 
        footer {
            width: 100%;
            height: 100px;
            text-align: center;
            background-color: pink;
            clear: both;
        }
    </style>
</head>
<body>
    <header>头部</header>
    <div class="box">
        <div class="left">左侧盒子</div>
        <div class="center">中部盒子</div>
        <div class="right">右侧盒子</div>
    </div>
    <footer>底部</footer>
</body>
</html>

 方式三:【定位实现双飞翼布局】

1、左侧盒子与右侧盒子设置固定宽度,高度固定值,添加左浮动

2、中间盒子宽度设置100%,设置左浮动,高度固定值

3、大盒子左右的padding值分别为左右侧盒子的宽度

4、左侧盒子 margin-left: -100%;,position: relative;,left: -“左侧盒子的宽度”;

5、右侧盒子 margin-left: -“右侧盒子的宽度”px;,position: relative;, right: -“右侧盒子的宽度”px;

6、头部和底部设置宽度100%,高度固定值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,body{
            margin: 0;
            padding: 0;
        }
         .box {
            padding: 0 200px;
            text-align: center;
        }
 
        header {
            width: 100%;
            height: 100px;
            text-align: center;
            background-color: pink;
        }
 
        footer {
            width: 100%;
            height: 100px;
            text-align: center;
            background-color: pink;
            clear: both;
        }
 
        .center {
            width: 100%;
            height: 200px;
            text-align: center;
            background-color: blue;
            float: left;
        }
 
        .left {
            float: left;
            margin-left: -100%;
            width: 200px;
            height: 200px;
            text-align: center;
            background-color: aqua;
            position: relative;
            left: -200px;
        }
 
        .right {
            margin-left: -200px;
            width: 200px;
            height: 200px;
            text-align: center;
            background-color: green;
            float: left;
            position: relative;
            right: -200px;
        }
    </style>
</head>
<body>
    <header>头部</header>
    <div class="box">
        <div class="center">中部盒子</div>
        <div class="left">左侧盒子</div>
        <div class="right">右侧盒子</div>
    </div>
    <footer>底部</footer>
</body>
</html>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Clover‘s Blog

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

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

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

打赏作者

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

抵扣说明:

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

余额充值