多列布局

多列布局

两列布局,一列定宽,另一列自适应

这里写图片描述
1、float + margin

<style>
    .content{
        width:150px;
        height:50px;
        border:3px solid #000;
    }
    .left{
        width:50px;
        height:50px;
        float:left;
        background-color:blue;
    }
    .right{
        margin-left:50px;
        height:50px;
        background-color:red;
    }
</style>
<div class="content">
    <div class="left"></div>
    <div class="right"></div>
</div>

2、margin设置负值解决

<style>
    .content{
        width:150px;
        height:50px;
        border:3px solid #000;
    }
    .left{
        width:50px;
        height:50px;
        float:left;
        background-color:blue;
    }
    .right{
        width:100%;
        margin-left:-50px;
        float:right;
        height:50px;
        background-color:red;
    }
</style>
<div class="content">
    <div class="right"></div>
    <div class="left"></div>
</div>

3、padding + position 解决

<style>
    .content {
        width:100px;
        padding-left:50px;
        position:relative;
        height:50px;
        border:3px solid #000;
    }
    .left{
        width:50px;
        height:50px;
        background-color:blue;
        position:absolute;
        left:0;
        top:0;
    }
    .right{
        width:100%;
        height:50px;
        background-color:red;
    }
</style>
<div class="content">
    <div class="left"></div>
    <div class="right"></div>
</div>

4、使用flex

<style>
    .content {
        width:150px;
        height:50px;
        border:3px solid #000;
        display:flex;
    }
    .left{
        width:50px;
        height:50px;
        background-color:blue;
    }
    .right{
        flex:1;
        background-color:red;
    }
</style>
<div class="content">
    <div class="left"></div>
    <div class="right"></div>
</div>

5、使用table

<style>
    .content {
        width:150px;
        height:50px;
        border:3px solid #000;
        display:table;
        table-layout:fixed
    }
    .left{
        width:50px;
        background-color:blue;
        display:table-cell;
    }
    .right {
        background-color:red;
        display:table-cell;
    }
</style>
<div class="content">
    <div class="left"></div>
    <div class="right"></div>
</div>

右列定宽,左列自适应;两列定宽,一列自适应;两侧定宽,中栏自适应等定宽+自适应的布局原理以上述一致!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值