css - 水平卷轴充满DIV? (自动宽度)

标签 css

我在制作无限期滚动的水平滚动条和自动缩放(宽度)以适应其中的子 div 时遇到了很多麻烦。很难解释,所以我做了一个 fiddle :

http://jsfiddle.net/M2b46/

HTML

<div class="scroller">
    <div class="box-container">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
    </div>
</div>

CSS

.scroller {
    overflow: scroll;
    border: 1px solid red;
}

.box-container {
    display: -moz-box;
    display: -webkit-box;
}

.box {
    float: left;
    width: 100px;
    height: 100px;
    background: #0088c4;
    margin: 1em;
}

我不想使用 box,因为它看起来有问题。在基于 Webkit 的浏览器上,由于某些原因,蓝色框不可见。在 Firefox 中,它完全符合我的预期。

如有任何帮助,我们将不胜感激!

最佳答案

我使用内联 block 得到了你的解决方案:

.box-container {
    display:block;
    width:100%;
    white-space:nowrap;
}

.box {
    display:inline-block;
    white-space:nowrap;
    width: 100px;
    height: 100px;
    background: #0088c4;
    margin: 1em;

}

demo

关于css - 水平卷轴充满DIV? (自动宽度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24227229/

相关文章:

html - 如何在 HTML/CSS 中对齐列表 ( ul > li ) 中的图像?

javascript - 带有图像的样式 knockout.js 单选按钮

jquery - 使用 Html、CSS 和 JQuery 自动调整出发板的大小

android - 如何在 Android 中突出显示 Html 标签内的选定字符串?

html - 防止表格单元格增加其宽度以包含宽内容

android - 全高流体图像和 div 在一行中。 Div 必须占据剩余的水平空间

CSS 类而不是媒体查询

javascript - 创建一个纵横比为 1 的 div :1 knowing only its height in percentage

CSS 工具提示在 Firefox 和 IE 中定位错误

javascript - 如何允许 svg 在链接中可点击