html – 使用Flexbox强制每行最小项目

前端之家收集整理的这篇文章主要介绍了html – 使用Flexbox强制每行最小项目前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用CSS flex,是否可以每行强制相同数量的项目?

我可以获取要包装的项目,但不能每行具有相同的数字(Fiddle).

  1. .container {
  2. display: flex;
  3. flex-flow: row wrap;
  4. position: relative;
  5. }
  6. .container > div {
  7. padding: 49px;
  8. flex: 1;
  9. Box-sizing: border-Box;
  10. }

这是我想要完成的图表:

enter image description here

最佳答案
可能您正在寻找数量查询,您可以根据列表中的项目数来更改样式

a list apart article

  1. .container {
  2. display: flex;
  3. flex-flow: row wrap;
  4. border: solid 1px green;
  5. }
  6. .container > div {
  7. flex: 1 0;
  8. background-color: lightgreen;
  9. height: 30px;
  10. margin: 5px;
  11. }
  12. .item:first-child:nth-last-child(3),.item:first-child:nth-last-child(3) ~ .item {
  13. flex-basis: 30%;
  14. }
  15. .item:first-child:nth-last-child(4),.item:first-child:nth-last-child(4) ~ .item {
  16. flex-basis: 40%;
  17. }

猜你在找的HTML相关文章