css3 - How to align child elements under flex layout?
淡淡烟草味
淡淡烟草味 2017-07-04 13:45:08
0
4
1746

As shown in the picture, I use justify-content:space-around;, but I hope that the second row of child elements can be aligned up and down with the first row. The number of child elements is not fixed. How to solve it?

淡淡烟草味
淡淡烟草味

reply all(4)
習慣沉默

justify-content:space-between;

滿天的星座

You may need some calculations:

.container {
  width: 510px;
  display: flex;
  flex-wrap: wrap;
  border: 1px solid #ccc;
}

.item {
  width: 150px;
  height: 150px;
  background: red;
  margin: 10px;
}
<p class="container">
  <p class="item"></p>
  <p class="item"></p>
  <p class="item"></p>
  <p class="item"></p>
  <p class="item"></p>
</p>

View online https://jsfiddle.net/zktf3oc5/

给我你的怀抱

flex The layout cannot achieve the effect you want when the parent container has a variable width.

世界只因有你

Flex implements layout, mainly because your idea breaks through the convention. If the horizontal layout is unsuccessful, use the vertical axis layout, set it to three columns, each column,
flex-direction:colomn;
justify-content:space-around;
Total Use the three columns again
justify-content :space-around;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template