css左边固定,右边自适应

css左边固定,右边自适应

HTML页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="container">
    <div class="left"></div>
    <div class="right"></div>
</div>
</body>
</html>

css

方法1:
左边div使用float:left;

<style>
       .left{
             float: left;
             width: 500px;
             height: 500px;
             background: red;
         }
         .right{
             height: 200px;
             background: #FF6633;
             overflow:auto;
         }
</style>

方法2:将外部容器div设置display:flex,flex-direction: row,将项目水平显示,正如一个行一样。并且将右边div设置flex:1,自适应宽度

<style>
      .container{
            display: -webkit-flex; !* Safari *!
            -webkit-flex-direction: row-reverse; !* Safari 6.1+ *!
            display: flex;
            flex-direction: row;

        }
        .left{
            background: red;
            width: 500px;
            height: 500px;
        }
        .right{
            flex:1;
            background: #FF6633;
            height: 200px;
        }
</style>

方法3:首先设置左边容器的宽度,和float值,然后设置右边容器的margin-left为左边容器的宽度

<style>
        .container{
            overflow: hidden; 
            *zoom: 1;
        }
        .left{
            float: left;
            background: red;
            width: 500px;
            height: 500px;
        }
        .right{
            background: #FF6633;
            margin-left: 500px;
            height: 200px;
        }
</style>

方法4:让左边容器脱离文档流,设置右边容器的margin-left为左边容器的宽度

<style>
        .container {
            *zoom: 1;
            position: relative;
        }
        .left {
            position: absolute;
            background: red;
            width: 500px;
            height: 500px;
            left: 0;
            top: 0;
        }
        .right {
            margin-left: 310px;
            background: #FF6633;
            height: 200px;
        }
</style>

方法5:将外部容器的display设置为table型,左右两边容器设置为table-cell型,但是这样的话会使左边和右边容器同高。

<style>
       .container {
            display: table;
            width: 100%;
        }
        .left {
            display: table-cell;
            background: red;
            width: 500px;
            height: 500px;
        }
        .right {
            display: table-cell;
            background: #FF6633;
        }
</style>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值