html - 嵌套 DIV 和水平滚动条

标签 html css

我有以下 DIV:

<div class="container">
    <div>Box 1</div>
    <div>Box 2</div>
    <div>Box 3</div>
</div>

以及以下 CSS:

.container{
    width:200px;
    height:100px;
    background-color:gray;
    overflow: auto;
}

.container div{
    width:80px;
    height:80px;
    background-color:red;
    display:inline-block;
}

返回这个结果: http://jsfiddle.net/becy1x62/

我想要一个水平滚动条而不是垂直滚动条。我不知道为什么容器内的 DIV 会断线。

谢谢。

最佳答案

您已将容器的宽度设置为 200 像素。这强制包装。为防止出现这种情况,请使用 white-space 属性:

.container {
    ...
    white-space: nowrap;
}

Demo

关于html - 嵌套 DIV 和水平滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28349437/

相关文章:

javascript - 将文件输入设置为 HTML 元素的背景

javascript - 使用 vuejs 和 axios 显示来自 JSON API 的数据

html - 无法调整图像的高度

html - 如何创建带页脚的响应式表格

Css 可重复属性

html - div 显示内联 block 在这种情况下无法按预期工作

html - 删除html表td之间的白线

html - 无法选择单选按钮 : issue with z-index?

html - DIV 中的 UL 不会更新高度

html - Div 不会拉伸(stretch)到窗口高度