强制水平扩展
对于一种缩略图水平滑动查看器
如何使水平滚动 div 内的 div 强制水平滚动 div,而不是到达末尾并开始新行?
我已经在使用 float: left 和 display: inline-block 但它们到达容器的末尾并创建一个新行,而不是强制容器水平扩展以适应它们,从而强制需要水平滚动条,
以便 div 框被迫这样做:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
<---->scroll
而不是:
[ ][ ][ ][ ]
[ ][ ][ ][ ]
代码:
<div style="overflow-x: scroll; overflow-y:hidden; width:500px; height: 140px;">
<div style="width: auto;">
<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 class="box"></div>
<div>
</div>
.box{
width: 100px;
height: 100px;
border: solid 1px black;
float:left;
display: inline-block;
}
For a sort of thumbnail horizontal sliding viewer
How can I make the divs inside the horizontal scrolling divs force the scrolling div horizontally, instead of reaching the end and starting a new line?
I am already using float: left and display: inline-block but they reach the end of their container and make a new line instead of forcing the container to expand horizontally to fit them and thus forcing the horizontal scrollbar to be needed
so the div boxes are force to do this:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
<---->scroll
instead of:
[ ][ ][ ][ ]
[ ][ ][ ][ ]
code:
<div style="overflow-x: scroll; overflow-y:hidden; width:500px; height: 140px;">
<div style="width: auto;">
<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 class="box"></div>
<div>
</div>
.box{
width: 100px;
height: 100px;
border: solid 1px black;
float:left;
display: inline-block;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要
float
和display:inline-block
,并且 float 不会这样做..所以您必须删除 float 规则,(添加解决方法IE7 及以下 *) - 当存在float
时,浏览器会忽略内部 div 上带有
white-space: nowrap
的display
属性You don't need
float
anddisplay:inline-block
, and floats won't do it.. so you have to remove the float rule, (add a workaround for IE7 and below *) - Whenfloat
is present browsers ignore thedisplay
propertywith
white-space: nowrap
on the inner div试试这个:
链接
Try this:
link