html,强制元素彼此相邻,即使被滚动父级切断

时间:2014-03-30 07:25:47

标签: html css

我希望在带有滚动条的窗口中,一系列元素彼此相邻。但是,他们继续转移到下一行。

我做了一个小伙伴:http://jsfiddle.net/922J5/

请注意,我不知道孩子的身高。

<div id = "parent">
    <div class = "child"></div>
    <div class = "child"></div>
    <div class = "child"></div>
    <div class = "child"></div>
</div>

#parent{overflow:scroll;
        width:200px;}

.child{
    background:red;
    margin:5px;
    width:100px;
    height:100px;
    display:inline-block;
}

1 个答案:

答案 0 :(得分:2)

将空白现在添加到父

#parent{overflow:scroll;
        width:200px;
    white-space:nowrap;}

.child{
    background:red;
    margin:5px;
    width:100px;
    height:100px;
    display:inline-block;
}

更新了代码。