Equal height rows in a flex container

Jinu Kurian

As you can see, the list-items in the first row have same height. But items in the second row have different heights. I want all items to have a uniform height.

Is there any way to achieve this without giving fixed-height and only using flexbox?

enter image description here

Here is my code

.list {
  display: flex;
  flex-wrap: wrap;
  max-width: 500px;
}
.list-item {
  background-color: #ccc;
  display: flex;
  padding: 0.5em;
  width: 25%;
  margin-right: 1%;
  margin-bottom: 20px;
}
.list-content {
  width: 100%;
}
<ul class="list">
  <li class="list-item">
    <div class="list-content">
      <h2>box 1</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    </div>
  </li>
  <li class="list-item">
    <div class="list-content">
      <h3>box 2</h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    </div>
  </li>

  <li class="list-item">
    <div class="list-content">
      <h3>box 2</h3>
      <p>Lorem ipsum dolor</p>
    </div>
  </li>

  <li class="list-item">
    <div class="list-content">
      <h3>box 2</h3>
      <p>Lorem ipsum dolor</p>
    </div>
  </li>
  <li class="list-item">
    <div class="list-content">
      <h1>h1</h1>
    </div>
  </li>
</ul>

Michael Benjamin

The answer is NO.

The reason is provided in the flexbox specification:

6. Flex Lines

In a multi-line flex container, the cross size of each line is the minimum size necessary to contain the flex items on the line.

In other words, when there are multiple lines in a row-based flex container, the height of each line (the "cross size") is the minimum height necessary to contain the flex items on the line.

Equal height rows, however, are possible in CSS Grid Layout:

Otherwise, consider a JavaScript alternative.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Equal height rows in flex-direction: column

From Dev

Equal height rows in flex-direction: column

From Dev

JQuery Equal Height Rows

From Dev

Equal height flex items in flex columns

From Dev

Flexboxes of equal height, content filling height of container

From Dev

Flexboxes of equal height, content filling height of container

From Dev

Make children of flex items equal height

From Dev

Splitting flex container into equal width part

From Dev

Bootstrap equal height rows inside equal height columns

From Dev

Equal height columns with display flex and its child height in percentage

From Dev

One flex item above two flex items on equal width rows

From Dev

CSS Flex: How to get equal heights in flex rows

From Java

How to make a flex item not fill the height of the flex container?

From Java

Equal height rows in CSS Grid Layout

From Dev

Using flexbox to get equal height rows, not columns

From Dev

Equal height for the rows to occupy maximum area of the screen

From Dev

CSS Bootstrap Equal Height 3 rows

From Dev

Can't get canvas element height to equal container height

From Dev

jquery set line-height equal to parent container height

From Dev

aligning columns in two rows of flex container

From Dev

Using CSS Flex to Make Elements Equal Height in a Row

From Dev

zebra striping rows in a flex container with flex-wrap:wrap

From Dev

How to create equal spacing between centered divs in a flex container

From Dev

Row flex container nested in column flex container with explicit height is rendered differently in Chrome and Firefox

From Dev

Make element take full height of flex item container

From Dev

Make flex items on second row take remaining height of container

From Dev

IE11 calculates the height of parent flex container incorrectly

From Dev

max-height not working on modal dialog in flex container with position:fixed

From Dev

How to make all children in a flex-container to have the same height

Related Related

  1. 1

    Equal height rows in flex-direction: column

  2. 2

    Equal height rows in flex-direction: column

  3. 3

    JQuery Equal Height Rows

  4. 4

    Equal height flex items in flex columns

  5. 5

    Flexboxes of equal height, content filling height of container

  6. 6

    Flexboxes of equal height, content filling height of container

  7. 7

    Make children of flex items equal height

  8. 8

    Splitting flex container into equal width part

  9. 9

    Bootstrap equal height rows inside equal height columns

  10. 10

    Equal height columns with display flex and its child height in percentage

  11. 11

    One flex item above two flex items on equal width rows

  12. 12

    CSS Flex: How to get equal heights in flex rows

  13. 13

    How to make a flex item not fill the height of the flex container?

  14. 14

    Equal height rows in CSS Grid Layout

  15. 15

    Using flexbox to get equal height rows, not columns

  16. 16

    Equal height for the rows to occupy maximum area of the screen

  17. 17

    CSS Bootstrap Equal Height 3 rows

  18. 18

    Can't get canvas element height to equal container height

  19. 19

    jquery set line-height equal to parent container height

  20. 20

    aligning columns in two rows of flex container

  21. 21

    Using CSS Flex to Make Elements Equal Height in a Row

  22. 22

    zebra striping rows in a flex container with flex-wrap:wrap

  23. 23

    How to create equal spacing between centered divs in a flex container

  24. 24

    Row flex container nested in column flex container with explicit height is rendered differently in Chrome and Firefox

  25. 25

    Make element take full height of flex item container

  26. 26

    Make flex items on second row take remaining height of container

  27. 27

    IE11 calculates the height of parent flex container incorrectly

  28. 28

    max-height not working on modal dialog in flex container with position:fixed

  29. 29

    How to make all children in a flex-container to have the same height

HotTag

Archive