L
L
LionG2019-11-05 19:12:02
css
LionG, 2019-11-05 19:12:02

How to make blocks on all lines the same height in flex when using wrap?

It turns out that for each row its own maximum height of the row element is taken. You can manually set the height but the content is dynamic. You can also write a script that will go through all the elements and set them to a certain height, but this is some kind of crutch.
5dc19ff290e4a253639325.png

<div class="parent">
  <div class="child"><div style="height:50px"></div></div>
  <div class="child"><div style="height:35px"></div></div>
  <div class="child"><div style="height:40px"></div></div>
  <div class="child"><div style="height:55px"></div></div>
  <div class="child"><div style="height:80px"></div></div>
  <div class="child"><div style="height:60px"></div></div>
</div>

div.parent {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 800px;
}

div.child {
  margin: 4px;
  display: flex;
  width: 250px;
  background-color: grey;
}

https://codepen.io/liong2/pen/gOOeMwX

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2019-11-05
@LionG

Grids to use

D
Daniil Postnov, 2020-10-06
@postnov_daniil

div.parent add property align-items: stretch.

div.parent {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  max-width: 800px;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question