css左侧固定,右侧自适应实现方式

实现方式:

  1. flex 布局
  2. position
  3. float 布局
  4. table
  5. gird 网格

html代码:

<div class="main">
    <div class="left"></div>
    <div class="right"></div>
</div>

第一种:flex布局

<style>
        .main{
            display: flex;
        }
        .left,.right{
            height: 100px;
        }
        .left{
            width: 200px;
            background: red;
        }
        .right{
            flex: 1;
            background: blue;
        }
</style>

第二种:position

<style>
        .main{
            position: relative;
        }
        .left,.right{
            height: 100px;
        }
        .left{
            width: 200px;
            background: red;
        }
        .right{
            position: absolute;
            top: 0;
            right: 0;
            left: 200px;
            background: blue;
        }
</style>

第三种:float布局

1、利用margin-left

<style>
        .left,.right{
            height: 200px;
        }
        .left{
            float: left;
            width: 200px;
            background: red;
        }
        .right{
            margin-left: 200px;
            background: blue;
        }
</style>

2、利用overflow:hidden

<style>
        .left,.right{
            height: 200px;
        }
        .left{
            float: left;
            width: 200px;
            background: red;
        }
        .right{
            overflow: hidden;
            background: blue;
        }
</style>

第四种:table

<style>
        .main{
            display: table;
            width: 100%;
        }
        .left,.right{
            display: table-cell;
            height: 100px;
        }
        .left{
            width: 200px;
            background: red;
        }
        .right{
            background: blue;
        }
</style>

第五种:gird网格

 <style>
        .main{
            width: 100%;
            height: 100px;
            display: grid;
            grid-template-columns: 200px auto; /*设置每一列的宽度,左200px,右自适应*/
        }
        .left{
            background: red;
        }
        .right{
            background: blue;
        }
</style>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值