【问题标题】:CSS Div fill remaining height [duplicate]CSS Div填充剩余高度[重复]
【发布时间】:2016-05-22 17:51:39
【问题描述】:

请看我的jsfiddle

我希望绿色中间的div 填充包装器div 的剩余空间,无论它有多少内容。

如果重要的话,我也包括引导程序。

【问题讨论】:

    标签: html css alignment


    【解决方案1】:

    给容器:

    display:flex;
    flex-direction:column;
    

    对于元素:

    flex:1;
    

    演示: https://jsfiddle.net/ugjfwbg4/1/

    body {
      background-color: red;
      height: 100%;
    }
    
    .wrap {
      height: 100vh;
      width: 100%;
      padding: 20px;
      background-color: yellow;
      display:flex;
      flex-direction:column;
    }
    
    .top {
      width: 100%;
      height: 50px;
      background-color: blue;
    }
    
    .mid {
      width: 100%;
      background-color: green;
      flex:1;
      display:flex;
      flex-direction:column;
    }
    
    .left{
      flex:1;
      width: 50%;
      background-color: red;
    }
    
    .bottom {
      width: 100%;
      height: 50px;
      background-color: blue;
    }
    <div class="wrap">
      <div class="top"></div>
    
      <div class="mid">
        
        <div class="left">left</div>
      </div>
    
      <div class="bottom"></div>
    </div>

    【讨论】: