多列布局

181 阅读1分钟

左边固定 右边自适应

方法一

<style>
    *{
        padding: 0;
        margin: 0;
    }
    #content{
        height: 300px;
        display: flex;
    }
    .left{
        width: 200px;
        height: 300px;
        background: red;
    }
    .right{
        height: 100%;
        background: pink;
        flex-grow: 1;
    }
</style>
<body>
    <div id="content">
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

方法二

*{
    padding: 0;
    margin: 0;
}
#content{
    width: 100%;
    height: 300px;
}
#left{
    float: left;
    width: 100px;
    height: 300px;
    background: red;
}
#right{
    float: right;
    width: calc(100% - 100px);
    height: 300px;
    background: aqua;
}
<div id="content">
    <div id="left"></div>
    <div id="right"></div>
</div>

左右固定 中间自适应

法一

<style>
    *{
        padding: 0;
        margin: 0;
    }
    #content{
        height: 300px;
        display: flex;
    }
    .left{
        width: 200px;
        height: 300px;
        background: red;
    }
    .center{
        height: 100%;
        background: #000;
        flex-grow: 1;
    }
    .right{
        width: 200px;
        height : 300px;
        background: pink;
      
    }
</style>
<body>
    <div id="content">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </div>
</body>

法二

*{
    padding: 0;
    margin: 0;
}
    #content{
    height: 300px;
    display: flex;
}
.left{
    width: 200px;
    height: 300px;
    background: red;
    flex: 0 0 200px;
}
.center{
    height: 100%;
    background: #000;
    flex: auto;
}
.right{
    width: 200px;
    height : 300px;
    background: pink;
    flex: 0 0 200px;
}

上下固定 中间自适应

 <style>
    body{

        height: 100%;
    }
    html{
        height: 100%;
    }
    *{
        padding: 0;
        margin: 0;
    }
    .top{
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 100px;
        background: red;
    }
    .center{
        position: absolute;
        top: 100px;
        bottom: 100px;
        right: 0;
        left: 0;
        background: #000;
    }
    .bottom{
        width:100%;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 100px;
        background: pink;
    }
</style>
<body>
    <div id="content">
        <div class="top"></div>
        <div class="center"></div>
        <div class="bottom"></div>
    </div>
</body>