html - div 上的水平滚动条具有动态内容和隐藏的 overflow-y

标签 html css dynamic scrollbar overflow

我需要一个只有一行图片的div,div里面的图片数量可以随时改变。所以我想要水平滚动条。 我有如下结构。我试图用 css 实现它,但不幸的是它不起作用。

<div id="scroll-wrapper">
  <div id="thumbnails">
    <div class="thumbnail-container active">
      <img src="foobar" />
    </div>
    <div class="thumbnail-container">
      <img src="bar" />
    </div>
  </div>
</div>

CSS 代码: http://jsfiddle.net/c622c3w9/2/

请注意,我不想要使用 javascript 的解决方案。

最佳答案

我必须删除 float: left 才能使滚动工作

 #thumbnails {
  padding-bottom: 10px;
  max-height: 50px;
  min-width: 100px;
  overflow-y: hidden;
  overflow-x: scroll; /*add this so you get bottom scrollbar*/
  white-space: nowrap; /*add this to stop images wrapping so thay stay on one line*/
}

.thumbnail-container {
  display: inline-block;
  position: relative;
  line-height: 5px;
  border: 2px solid steelblue;
  margin: 3px;
  display: inline-block;
  /*float: left; remove this otherwise scroll will not work*/
  margin-bottom: 15px !important;
}

http://jsfiddle.net/c622c3w9/3/

关于html - div 上的水平滚动条具有动态内容和隐藏的 overflow-y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40178890/

相关文章:

html - 与停用 CSS 中的悬停效果相关的问题

html - 将(字体很棒的)图标在图像上水平和垂直居中

html - 为什么图像源为空时添加黑线?

C++:动态位集

html - 如何在 50% 的区域 CSS 上设置背景色

html - BR标签有高度吗?

java - 在 Java 中创建动态给定类的实例

javascript - 在javascript中初始化 'multidimensional'对象

jquery - 将标签与复选框水平对齐

javascript - Jquery:当文档准备好时,如何将我的Jquery中的所有数据返回到html?