Equal height children of flex items

This is not possible with flexbox or CSS, in general.

An initial setting of a flex container is align-items: stretch. This causes flex items to expand the full length of the cross axis. This is what is known as “flex equal height columns”.

Here are a few notes to keep in mind:

  • Equal height columns apply only to the children of a flex container. In other words, the flex items must have the same parent. Otherwise, the equal height feature doesn’t apply.

Your question:

I want all the h2 headings of the row to be the same height. Is this possible in some way?

Not with CSS. Because the h2‘s exist in different containers, they aren’t siblings (they’re more like cousins), so equal heights don’t apply.

  • Equal height columns in flexbox apply only to one flex line. Items on other lines, created by wrapping, establish their own equal height line. This means that equal height columns do not work in a multi-line flex container.

  • The align-self property can be used on individual flex items to override align-items, which can break the equal height feature.

  • By specifying a height on a flex item (e.g. height: 300px), both align-items and align-self are overridden for that item, and the equal height setting is ignored.

  • This post focuses on a container with flex-direction: row. If the container is flex-direction: column, then equal height becomes equal width. Here’s a detailed review: Make flex items take content width, not width of parent container

More details:

Duplicate posts:

Leave a Comment