jquery - 使内部div比外部div宽

标签 jquery html css width

我有两个 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/

相关文章:

html - 一个 flex/网格元素设置 sibling 的大小限制

具有标记约束的 CSS 定位(边距/填充)

html - cakephp CSS问题

javascript - 复选框结构,如果选中单个子复选框,则应自动选中父复选框

asp.net - Jquery日期选择器: validate date mm/dd/yyyy

单击另一个 li 时的 jQuery slideToggle li

jquery - 需要 setOnLoadCallback() 替代方案

HTML 导航栏复选框不可点击

jquery - 在表格和页码之间添加微小的空格

javascript - jQuery 动态加载图像无法显示多个图像如何替换 src= 并且不附加到它