How to force child div to be 100% of parent div's height without specifying parent's height?

前端 未结 26 2004
刺人心
刺人心 2020-11-22 06:52

I have a site with the following structure:

<
26条回答
  •  孤城傲影
    2020-11-22 07:37

    You use CSS Flexbox

    .flex-container {
      display: flex;
      background-color: DodgerBlue;
    }
    
    .flex-container > div {
      background-color: #f1f1f1;
      margin: 10px;
      padding: 20px;
      font-size: 30px;
    }
    
    
    
    
    
    
    
    1
    2
    3

    A Flexible Layout must have a parent element with the display property set to flex.

    Direct child elements(s) of the flexible container automatically becomes flexible items.

提交回复
热议问题