html - 如何连续显示多个图像始终覆盖整个宽度

标签 html css responsive-design

我想在一个框中显示相同高度和宽度(154 像素 x 125 像素)的多张图片(最多 24 张)。这很容易做到。但问题是当没有足够的空间来调整最后一张图像时,它会留下空白。我希望图像在任何屏幕尺寸下自动调整到框的全宽。我该怎么做?

.tab-content {
    background-color: #0c1011;
    padding: 0px 0px;
    margin-bottom: 0px;
    display: block;
    overflow: hidden;
}
.tab-pane img {
    display: inline-block;
    float: left;
}
.tab-pane a {
    display: block;
}
.img-responsive {
    display: block;
    height: auto;
    max-width: 100%;
}
<div class="tab-content clearfix">
  <div class="tab-pane active" id="1a">
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
   <a href="#">
      <img src="http://lorempixel.com/154/125/" class="img-responsive">
   </a>
  </div>
</div>

enter image description here

这是代码笔:

https://codepen.io/nitingsingh/pen/rJeROm

最佳答案

您可能想看看 CSS3 中的 flexbox 。 引用:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

这应该对你有帮助。检查这个:

body {margin:0} /* addition */

.tab-content {
  background-color: #0c1011;
  padding: 0; /* shorthand */
  margin-bottom: none;
  /*display: block; by default*/
  overflow: hidden;
}

.tab-pane {
  display: flex;
  flex-wrap: wrap;
}

.tab-pane a {
  flex: 1 0 auto; /* shorthand | flex-grow: 1; | flex-shrink: 0; | flex-basis: auto */
}

.img-responsive {
  display: block;
  width: 100%;
}
<div class="tab-content clearfix">
  <div class="tab-pane active" id="1a">
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
    <a href="#">
      <img src="http://lorempixel.com/154/125/" alt="" class="img-responsive">
    </a>
  </div>
</div>

关于html - 如何连续显示多个图像始终覆盖整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48617309/

相关文章:

css - html中的多表对齐

php - Xpath 删除文本之间的空格

html - 使用 bootstrap 在行内将 2 张图片彼此居中

html - CSS 中宽度为 100% 的图像的负边距

css - 根据宽度大小使 div 变小和变大

html - 嵌套链接重叠

javascript - fadeOut 不会在 Firefox 中正确设置动画

javascript - 汉堡菜单不隐藏在菜单点击

javascript - 背景图像、3 个透明 png 按钮、三个链接和响应式。可能的?

css - HTML5 无响应