html - 使用 HTML 和 CSS 创建 4x5 图像网格

标签 html css

我正在尝试创建一个 4x5 图像网格。但我无法让图像正确对齐。并具有正确的响应大小。我正在尝试创建类似这样的东西 dealsource.tech .感觉自己真的很失败。 任何见解都会非常有帮助。

.row-one {
  list-style: none;
  font-size: 0px;
  margin-left: -2.5%;
}

.row-one li {
  display:inline-block;;
  padding: 10px;
  margin: 0 0 2.5% 2.5%;
  font-size: 16px;
  font-szie: 1rem;
  vertical-align: top;
  box-shadow: 0 0 5px #ddd;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}

.product-image img {
  max-width: 50%;
  height:auto;
  margin:0 0 10px;
}

.product-description h3 {
  text-align: center;
  margin: 0 0 5px;
}

.product-description p {
  text-align: center;
  font-size: .9em;
  line-height: 1.5em;
  color: #999;
}
<section class="section-three">
 <ul class="row-one">
  <li>
   <figure class="product-image"><img src="images/graphics cards/Asus GeForce GTX2.jpg" alt="Asus GeForce GTX2"></figure>
   <figcaption class="product-description"><h3>Asus GeForce GTX2</h3>
    <p>From $800 to <em>$500</em></p>
    <p>Dec 29, 2016</p></figcaption>
  </li>
  <li>
   <figure class="product-image"><img src="images/graphics cards/Gigabyte GT 420.jpg" alt="Gigabyte GT 420"></figure>
   <div class="product-description"><h3>Asus GeForce GTX2</h3>
    <p>From $800 to <em>$500</em></p>
    <p>Dec 29, 2016</p></div>
  </li>
  <li>
   <figure class="product-image"><img src="images/graphics cards/Gigabyte Geforce GTX 1050.jpg" alt="Gigabyte Geforce GTX 1050"></figure>
   <figcaption class="product-description"><h3>Asus GeForce GTX2</h3>
    <p>From $800 to <em>$500</em></p>
    <p>Dec 29, 2016</p></div></figcaption>
  </li>
  <li>
   <figure class="product-image"><img src="images/graphics cards/Gigabyte     GT 420.jpg" alt="Gigabyte GT 420"></figure>
   <div class="product-description"><h3>Asus GeForce GTX2</h3>
    <p>From $800 to <em>$500</em></p>
    <p>Dec 29, 2016</p></div>
  </li>
 </ul>
</section>

最佳答案

最简单的方法是通过 flex-box

https://jsfiddle.net/ASAP/qbxtgmf0/1/

.flexbox {
  display: flex;
  flex-flow: row wrap;
  width: 440px; /* 4 items * item width(100+5+5) = 440 */
}

.flexbox .flex-item {
  padding: 5px;
}

关于html - 使用 HTML 和 CSS 创建 4x5 图像网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41513226/

相关文章:

html - 在 CSS 中控制(链接)按钮的颜色

css - 谷歌字体在桌面上加载,但不是在移动设备上?

html - 如何将图像放在轮播 slider 的顶部

html - 如何让特定段落向左浮动,图像向右浮动

html - 背景图片消失html/css

html - 根据父级的高度设置宽度

javascript - 如何使用 Canvas 将圆与线连接起来

javascript - 在按键上应用滚动动画,使其与鼠标单击时的滚动动画相同

javascript - 试图让我的导航栏在我点击它时关闭?

css - Rails 输出错误的 Assets 路径