html - 在父 div 中等间隔 div?

标签 html css

应该足够简单。我有一个宽度为 1100px 的 div,其中包含宽度为 300px 的 div。我需要将它们均匀地隔开,并在 1100px 宽度内不再适合时清除到下一行。最好的方法是做到这一点?我从来不需要这样做。

最佳答案

我想这就是您要找的。您可以使用 nth-of-type 为中间框添加边距

.background{
  background: black;
  width: 1100px;
  margin: auto
  overflow: hidden;
}

.box{
  width: 300px;
  height: 300px;
  float: left;
  margin: 0 0 20px
}

.box:nth-of-type(3n+2){
  margin: 0 100px 20px;
}

FIDDLE

关于html - 在父 div 中等间隔 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27351334/

相关文章:

html - 行内 block 不完全一样

python - 使用Python登录投资者商报并获取股票数据

jquery - 具有 Bootstrap 4 性能的 Angular 5?

css - 外部相对 img 的 div 溢出

css - 如何使用 css 将 center1 直接定位在 center3 下方

html - 跳过 HTML 表格中的 <td>

html - 向滚动条添加箭头

html - 如何跟踪新功能到 (WHATWG) HTML 标准

css - 如何在 React Native 中使用 flexbox 使一项居中?

css - 将列表项中的 div 居中