假设我有一个家长和一群孩子
<div id="container">
<div class="child">stuff</div>
<div class="child">stuff</div>
<div class="child">stuff</div>
<div class="child">stuff</div>
<div class="child">stuff</div>
<div class="child">stuff</div>
etc.
</div>
如何使子div水平排列(inline-block
)并禁用溢出y滚动条,同时强制子div继续生成左-右滚动条?
http://jsfiddle.net/cpofvohr/
发布于 2015-01-14 18:50:53
您需要将white-space: pre
或white-space: nowrap
添加到#container
中以防止包装。
更新Fiddle
var div = document.getElementById("container");
for (i = 1; i < 40; i++) {
var div2 = document.createElement("div");
div2.className = "child";
var text = document.createTextNode(i)
div2.appendChild(text);
div.appendChild(div2);
}
.child {
background-color: #D8D8D8;
height: 375px;
width: 30px;
margin: 3px;
display: inline-block;
}
#container {
width: auto;
min-width: 100px;
max-height: 400px;
overflow-x: scroll;
position: relative;
min-height: 100%;
white-space: pre;
}
<div id="container"></div>
https://stackoverflow.com/questions/27950289
复制相似问题