html - 图像元素在 Div 中换行

标签 html css sass

如果图像数量超过 div 的宽度,我试图让 div 水平滚动。不幸的是,在尝试了我在堆栈上找到的所有内容之后,一旦图像数量超过了 div 的宽度,它就会被推到一个新行,而不是继续在具有滚动能力的同一行上。下面是 handlebars 模板和 sass。

https://jsfiddle.net/horuuf33/6/

.colourway-extension-wrapper {
  position: absolute;
  bottom: 0;
  max-height: 185px;
  width: 100%;
  overflow: hidden;
}

.facets-item-cell-grid-colourway {
    height: 0;
    background: rgba(255,255,255,0.5);
    overflow-x: scroll;
    overflow-y: hidden;
    width: auto;
    max-height: 185px;
    white-space: nowrap;

    -webkit-transition: height 0.5s;
    -moz-transition: height 0.5s;
    -ms-transition: height 0.5s;
    -o-transition: height 0.5s;
    transition: height 0.5s;
}

.item-colourway-wrapper {
  max-width: 100px;
  width: 100px;
  float: left;
  margin-right: 10px;
  visibility: hidden;
  text-align: center;
  text-transform: uppercase;
  font-weight: lighter;
}

.facets-item-cell-grid {
    &:hover {
        [class="facets-item-cell-grid-colourway"] {
            height: 185px;
        }
    [class="item-colourway-wrapper"] {
      visibility: initial;
    }
    }
}

模板:

{{#if isMoreColours}}
<div class="facets-item-cell-grid-colourway">


    {{#each option}}
        <div class="item-colourway-wrapper">
            <img class="facets-item-cell-colourway-img" src="{{resizeImage this.url 'thumbnail'}}" alt="{{this.altimagetext}}" itemprop="image"/>
            <p>{{this.colour}}</p>
        </div>
    {{/each}}


</div>
{{/if}}

最佳答案

只需将 .item-colourway-wrapper 中的 float: left; 替换为 display: inline-block;

JSFiddle

.colourway-extension-wrapper {
  position: absolute;
  bottom: 0;
  max-height: 185px;
  width: 100%;
  overflow: hidden;
}

.facets-item-cell-grid-colourway {
  height: 185px;
  background: rgba(0, 0, 0, 1);
  overflow-x: scroll;
  overflow-y: hidden;
  width: auto;
  max-height: 185px;
  white-space: nowrap;
}

.item-colourway-wrapper {
  max-width: 100px;
  width: 100px;
  display: inline-block;
  margin-right: 10px;
  text-align: center;
  text-transform: uppercase;
  font-weight: lighter;
  background: #FFF;
}
<div class="facets-item-cell-grid-colourway">
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
  <div class="item-colourway-wrapper">
    <img class="facets-item-cell-colourway-img" src="" itemprop="image" />
    <p>Colour</p>
  </div>
</div>

关于html - 图像元素在 Div 中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49864003/

相关文章:

python - 无法加载 Bootstrap css 文件

html - 在 Bootstrap 中创建隐藏文本(然后显示它)?

HTML 元素与我的本地主机不在我的域(和其他人的本地主机)上的同一位置

html - 如何使用有效的 XHTML/CSS 制作 2 列列表?

html - 基于表格的菜单不会响应@media 查询

javascript - 如何更改滚动上的 div 位置(取决于滚动方向)?

javascript - 循环数组并获取 Li 的每 4 个元素并将其添加到 Ul 列表

html - 在自动填充容器中居中网格元素

html - 超轻型 YouTube 播放器

css - 添加了 Sass、IE 过滤器和额外的空格