如何在缩小父级时显示内联块而不在新行上断开它们

时间:2014-06-10 13:44:16

标签: html width css

我在容器中有2列(内联块)(100%宽度)。

  1. 左侧列必须具有最小宽度,例如200px,宽度:25%。

  2. 右侧栏的宽度为:75%

    <style>
    .outer {
        width: 100%;
        border: 1px solid black;
    }
    .left, .right {
        display:inline-block;
    }
    .left {
        min-width: 200px;
        width: 25%;
        background-color: #dcc2c2;
    }
    .right {
        width: 75%;
        background-color: #d0dee8;
    }
    </style>
    
        <div class="outer">
            <div class="left">left</div>
            <div class="right">right</div>
        </div>
    
  3. 在调整大小时达到最小宽度之前,列并排放置,这是我想要的,但是一旦最小宽度开始,右列就会落在下一行。

    如何使正确的列缩小但不会落在下一行?

    Link to JSFiddle

2 个答案:

答案 0 :(得分:33)

white-space:nowrapoverflow:hidden添加到外部:

.outer {
    width: 100%;
    border: 1px solid black;
    white-space:nowrap;
    overflow:hidden;
}

<强> jsFiddle example

答案 1 :(得分:6)

您可以使用calc(100% - 200px)保留空格以使其正常工作!

.right {
    width:75%;
    max-width:calc(100% - 200px);
    background-color: #d0dee8;
}

Fiddle

Info about css3 calc()