css两栏布局,左边定宽,右边自适应

左右两栏布局

HTML部分

<body>
    <div class="box">
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

CSS部分

html,body{
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

1. 使用flex布局

        .box{
            width: 100%;
            height: 100%;
            display: flex;
        }
        .left{
            width: 200px;
            background: red;
        }
        .right{
            flex: 1;
            background: yellowgreen;
        }

2. 使用float布局

        .box{
            width: 100%;
            height: 100%;
        }
        .left{
            width: 200px;
            height: 100%;
            background: red;
            float: left;
        }
        .right{
            padding-left: 200px;
            height: 100%;
            background: yellowgreen;
        }

3. 使用绝对定位

        .box{
            width: 100%;
            height: 100%;
            position: relative;
        }
        .left{
            width: 200px;
            height: 100%;
            background: red;
            position:absolute;
            left: 0;

        }
        .right{
            height: 100%;
            background: yellowgreen;
            margin-left: 200px;
        }

上下布局,上部分定宽,下面部分高度自适应

HTML部分

<body>
    <div class="box">
        <header></header>
        <main></main>
    </div>
</body>

CSS部分

        html,body{
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        .box{
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
        }
        header{
            width: 100%;
            height: 100px;
            background: #333;
        }
        main{
            width: 100%;
            height: 100%;
            background: yellowgreen;
            position: absolute;
            top: 100px;
            left: 0;
            right: 0;
            bottom: 0;
        }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值