我有两个 div。外部 div 的名称是 scroll_main ,内部 div 的名称是 scroll_holder 。外部 div 的宽度为 750px,overflow 设置为 auto。在内部 div 中,我添加了一些具有固定宽度和高度并向左浮动的 div。所以我想将内部 div 的宽度设置为自动,以便内部部分的所有包含 div 显示在一行中。我想从左向右滚动。是否可以?谢谢
这是html
<div class="scroll_main">
<div class="scroll_holder">
<div style="width:400px; height:400px; background:#333; float:left; margin:10px"></div>
<div style="width:400px; height:400px; background:#999; float:left;margin:10px"></div>
<div style="width:400px; height:400px; background:#ccc; float:left;margin:10px"></div>
<div style="width:400px; height:400px; background:#22b1b5; float:left;margin:10px"></div>
<div style="width:400px; height:400px; background:#333; float:left; margin:10px"></div>
<div style="width:400px; height:400px; background:#999; float:left;margin:10px"></div>
</div>
</div>
这是我尝试应用的 css
.scroll_main {
height: 450px;
margin: 0 auto;
max-width: 97%;
overflow: auto;
position:relative;
width:750px
}
.scroll_holder{overflow:hidden; margin:5px; width:750px; overflow:auto }
最佳答案
选项 1
here我认为您正在寻找的是什么(尽管尺寸较小):
#images {
overflow-y:hidden;
overflow-x:scroll;
height:80px;
width:150px;
border:solid 1px #c4c4c4;
}
#images2
{
width:300px;
}
#images img
{
display:block;
padding:5px;
cursor:pointer;
float:left;
}
选项 2
this演示了使用此 CSS 的另一种技术:
div {
overflow:hidden;
}
#frame {
width:600px;
padding:8px;
border:1px solid black;
}
#thumbnails_container {
border:1px solid black;
padding:4px;
overflow-x:scroll;
height:200px;
}
.thumbnail {
border:1px solid black;
margin-right:4px;
width:100px; height:75px;
float:left;
}
.thumbnail img {
width:100px; height:710px;
}
如果您将它用于图像,这也允许使用缩略图。
另一种选择是使用 no-wrap
来阻止 div 换行
关于jquery - 使内部div比外部div宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27104950/