两栏布局*6

方法1:float:left;margin-left:xxpx;

<style type="text/css">
    .container{
        width: 100%;
        height: 500px;
    }
    .one{
        width: 200px;
        height: 100%;
        float: left;
        background-color:brown;

    }
    .two{
        width: 100%;
        height: 100%;
        margin-left:200px;
        background-color: cornflowerblue;
    }
</style>

<div class="container">
    <div class="one"></div>
    <div class="two"></div>
</div>

方法2:父:position:relative;自适应块:position:absolute;left:xxpx;top:0px;

<style type="text/css">
   .container{
       width: 100%;
       height: 500px;
       position: relative;
   }
   .one{
       width: 200px;
       height: 100%;
       background-color:brown;

   }
   .two{
       width: 100%;
       height: 100%;
       position: absolute;
       left: 200px;
       top: 0;
       background-color: cornflowerblue;
   }
</style>

<div class="container">
   <div class="one"></div>
   <div class="two"></div>
</div>

方法3:flex布局,父:display:flex;自适应部分:flex:1;

<style type="text/css">
    .container{
        width: 100%;
        height: 500px;
        display: flex;
    }
    .one{
        width: 200px;
        height: 100%;
        background-color:brown;

    }
    .two{
        width: 100%;
        height: 100%;
        flex: 1;
        background-color: cornflowerblue;
    }
</style>

<div class="container">
    <div class="one"></div>
    <div class="two"></div>
</div>

方法4:表格布局,父:display:table;固定宽度子:width:xxpx;display:table-cell;自适应子:display:table-cell;无width

<style type="text/css">
    .container{
        width: 100%;
        height: 500px;
        display: table;
    }
    .one{
        width: 200px;
        height: 100%;
        display: table-cell;
        background-color:brown;

    }
    .two{
        height: 100%;
        display: table-cell;
        background-color: cornflowerblue;
    }
</style>

<div class="container">
    <div class="one"></div>
    <div class="two"></div>
</div>

方法5:左右两栏都float:left;左栏:width:xxpx;右边栏:width:calc(100% - xxpx);

<style type="text/css">
    .container{
        width: 100%;
        height: 500px;
    }
    .one{
        width: 200px;
        height: 100%;
        float: left;
        background-color:brown;

    }
    .two{
        height: 100%;
        float: left;
        width: calc(100% - 200px);/* 此处一定注意   !!!! 减号两边必须有空格*/
        background-color: cornflowerblue;
    }
</style>

<div class="container">
    <div class="one"></div>
    <div class="two"></div>
</div>

方法6:左右两元素都设置inline-block,右边元素宽度使用calc进行计算。但需要解决inline-block时,标签换行会渲染为一个空格换行符/空格间隙问题,解决方法其一:需要在父元素中添加display: table;word-spacing:-1em;

<style type="text/css">
    .container{
        width: 100%;
        height: 500px;
        display: table;
        word-spacing:-1em;
    }
    .one{
        width: 200px;
        height: 100%;
        display: inline-block;
        background-color:brown;

    }
    .two{
        height: 100%;
        width: calc(100% - 200px);
        display: inline-block;
        background-color: cornflowerblue;
    }
</style>

<div class="container">
    <div class="one"></div>
    <div class="two"></div>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值