html - 即使容器不换行, float div 也会换行?

标签 html css

有一些关于此的问题,但我还没有找到一个好的答案。已经找了几个小时了。

这是我的 jsfiddle: http://jsfiddle.net/foreyez/Mr2ER/

我有一些简单的标记:

<div class='container'>
    <div class='box1'></div>
    <div class='box2'></div>
    <div class='box3'></div>
</div>

和 CSS:

.container {
    white-space:nowrap;
}

.box1 {
    width:200px;
    height:200px;
    background:red;
    float:left;
}

.box2 {
    width:200px;
    height:200px;
    background:green;
    float:left;
}

.box3 {
    width:200px;
    height:200px;
    background:blue;
    float:left;
}

然而,当窗口足够小时,盒子仍然会环绕。有什么建议么? 注意:我想保持这个 float:left,所以请不要使用 inline-block 解决方案。

最佳答案

如果您将 width:600px; 添加到 .container 中,它将强制它们保持内联。

这是你的 updated JSFiddle

关于html - 即使容器不换行, float div 也会换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22178115/

相关文章:

html - 如何使用 angularjs 将选项卡标题与正文分开?

html - 模态弹出窗口位于 slider 后面

css - 在 Firefox、Internet Explorer 和 Safari 中的不同定位?

javascript - 过渡时间不一样

html - div的CSS变换中心

javascript - 使用鼠标添加和删除位图图像 "click"- JavaScript/CreateJS

html - 在 Internet Explorer 的头部注入(inject) Javascript 字体

html - 为什么无论我做什么都不能更改复选框颜色?

javascript - CSS动画卡住

html - 将 DIV 拉伸(stretch)到整个页面宽度,但也可以根据浏览器边框自动调整大小