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

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

I have a site with the following structure:

<
26条回答
  •  猫巷女王i
    2020-11-22 07:39

    For the parent:

    display: flex;
    

    You should add some prefixes, http://css-tricks.com/using-flexbox/.

    Edit: As @Adam Garner noted, align-items: stretch; is not needed. Its usage is also for parent, not children. If you want to define children stretching, you use align-self.

    .parent {
      background: red;
      padding: 10px;
      display:flex;
    }
    
    .other-child {
      width: 100px;
      background: yellow;
      height: 150px;
      padding: .5rem;
    }
    
    .child {  
      width: 100px;
      background: blue;
    }
    Only used for stretching the parent

提交回复
热议问题