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

后端 未结 5 639
故里飘歌
故里飘歌 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 09:54

    If I understood correctly, you are looking for the align-items property, which defines the layout along the cross axis, in this case vertically.

    You can find a good overview here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

    .flexbox {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: stretch; // <-- stretch vertical (default value, can be omitted here)
      align-content: center;
    }
    
    .box {
        padding: 1em;
        text-align: center;
        margin: 1em;
    }
    
    .box--yellow {
      background-color: yellow;
    }
    
    .box--blue {
      background-color: blue;
      color: white;
    }
    yellow
    some
    cool
    text

提交回复
热议问题