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

后端 未结 5 628
故里飘歌
故里飘歌 2020-11-28 09:29

I need to stretch yellow child to fill all height of parent. Without setting parent height. Height of parent should be dependent on blue child text. https://jsfiddle.net

5条回答
  •  一整个雨季
    2020-11-28 10:00

    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

    some
    cool
    text

提交回复
热议问题