css两栏布局问题

现在我有两个div要并排布局
我想让右边的div宽度固定,并固定在屏幕最右侧
左侧的div宽度自适应
同时右侧div用v-if控制显隐
当右侧div隐藏时,左侧div自动布满整个屏幕

请问这两个div的css该怎么写?

阅读 2.3k
3 个回答

可以使用flex布局弹性盒模型

<html>
    <head>
        <title>flex</title>
    </head>
    <style type="text/css">
        .wrap{
            display: flex;
            height: 500px;
        }
        .left{
            width: 100px;
            background-color: red;
        }
        .right{
            flex:1;
            width: 100%;
            background-color: black;
        }
    </style>
    <body>
        <div class="wrap">
            <div class="left"></div>
            <div class="right"></div>
        </div>
        
    </body>
</html>

上面兄弟的稍微调整一下,就可以了
.wrap{

    display: flex;
    height: 500px;
}
.left{
    flex:auto;
    background-color: red;
}
.right{
    width: 200px;
    background-color: black;
}

兼容IE浏览器 table布局

<style>
    .layer {
        width: 100%;
        display: table;
        word-break: break-all;
    }
    .left {
        background: red;
    }
    .right {
        background: green;
        width: 200px;
        display: table-cell;
    }
</style>
<div class="layer">
    <div class="left">12</div>
    <div class="right">232right232right232right232right232right232right232right</div>
</div>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题