左右布局,圣杯布局(弹性盒子写)

左右布局:

左边固定,右边自适应

<!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>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            /* 转换成弹性盒子,自动横向排列 */
            display: flex;
        }
        .left,.right{
            width: 200px;
            height: 300px;
            background-color: red;
        }
        .center{
            height: 400px;
            background-color: pink;

            /* 自适应宽度 flex:1;*/
            flex: 1;
            text-align: right;
        }
    </style>
</head>
<body>
    <div class="left">left</div>
    <div class="center">center</div>
    <!-- <div class="right">right</div> -->
</body>
</html>

圣杯布局:

中心:高度自适应,左右两侧宽度固定死,中间的宽度自适应

<!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>
        *{
            padding: 0;
            margin: 0;
        }
        html,body{
            /* 高度100%,下一级的属性100%才能生效 */
            height: 100%;
        }
        body{
            display: flex;
            flex-direction: column;
        }
        header{
            height: 100px;
            background-color: red;
        }
        main{
            background-color: pink;
            /* 转换成弹性盒子 */
            flex: 1;
            display: flex;
        }
        main .left{
            width: 100px;
            height: 100%;
            background-color: aqua;
        }
        main .right{
            width: 100px;
            height: 100%;
            background-color: rgb(12, 244, 171);
        }
        main .center{
            /* 宽度自适应:  flex: 1 ; */
            flex: 1;
            /* 高度自适应 */
            height: 100%;
            background-color: blue;
        }
        footer{
            height: 100px;
            background-color: green;
        }
    </style>
</head>
<body>
    <header>header</header>
    <main>
        <div class="left">left</div>
        <div class="center">center</div>
        <div class="right">right</div>
    </main>
    <footer>footer</footer>
</body>
</html>
<!-- 
    圣杯布局:
        上:高度固定死
        中:高度自适应
            左:宽度固定死
            中:宽度自适应
            右:宽度固定死
        下:高度固定死
 -->

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值