How to stretch flex child to fill height of the container?

When using Flexbox, the major mistake is to start using height: 100% all over.

We are used to that in many cases, though when it comes to Flexbox, it often breaks it instead.

The solution is simple, just remove the height: 100%, and it will work automatically.

The reason it does, is for flex item in row direction (the default), the align-items control the vertical behavior, and as its default is stretch this just work as is.

Stack snippet

<div style="display: flex">
  <div style="background-color: yellow; width: 20px">
  </div>
  <div style="background-color: blue">
    some<br> cool<br> text
  </div>
</div>

Leave a Comment