html - 使用 flexbox 将图像排成一行

标签 html css flexbox

我想将一堆图像彼此相邻放置(连续 4 张),将第 5 张放在下一行...

图像宽度应为行的 1/4。

我正在尝试使用 flex-boxes 找到解决方案,但没有任何线索......

<h2>Students</h2>
<div class="content">
  <img class="student" src="http://placehold.it/400x400">
  <img class="student" src="http://placehold.it/400x400">
  <img class="student" src="http://placehold.it/400x400">
  <img class="student" src="http://placehold.it/400x400">
  <img class="student" src="http://placehold.it/400x400">
  <img class="student" src="http://placehold.it/400x400">
  <img class="student" src="http://placehold.it/400x400">
</div>

最佳答案

.content {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.content > div {
  width: 25%;
  padding: 0 10px 10px 0;
  box-sizing: border-box;
}

.content > div  img {
  width: 100%;
}
<h2>Students</h2>
<div class="content">
  <div><img class="student" src="http://placehold.it/400x400"></div>
  <div><img class="student" src="http://placehold.it/400x400"></div>
  <div><img class="student" src="http://placehold.it/400x400"></div>
  <div><img class="student" src="http://placehold.it/400x400"></div>
  <div><img class="student" src="http://placehold.it/400x400"></div>
</div>

这就是你想要的?

关于html - 使用 flexbox 将图像排成一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41838344/

相关文章:

javascript - .load() 不适用于 ul li click

html - 如何应用边距以使元素不超过 100% 宽度?

javascript - 在 div 元素中显示 javascript 消息

google-chrome - 更复杂的 Flex 布局

html - 仅使用 CSS Flexbox 控制垂直堆叠元素的顺序

javascript - 文本区域中空格后@的正则表达式

javascript - 折叠的导航按钮不适用于 Twitter Bootstrap 设计的移动设备

网页 | CSS : Issues with hamburger menu

html - 如何正确使用 flexbox 在 HTML/CSS 中实现 BorderLayout?

html - 扩展名为scss如何申请