How to fill 100% of remaining height?

后端 未结 8 1060
眼角桃花
眼角桃花 2020-12-04 11:25
+--------------------+
|                    |
|                    |
|                    |
|                    |
|         1          |
|                    |
|            


        
相关标签:
8条回答
  • 2020-12-04 11:44

    I know this is an old question, but nowadays there is a super easy form to do that, which is CCS Grid, so let me put the divs as example:

    <div id="full">
      <div id="header">Contents of 1</div>
      <div id="someid">Contents of 2</div>
    </div>
    

    then the CSS code:

    .full{
      width:/*the width you need*/;
      height:/*the height you need*/;
      display:grid;
      grid-template-rows: minmax(100px,auto) 1fr;
     }
    

    And that's it, the second row, scilicet, the someide, will take the rest of the height because of the property 1fr, and the first div will have a min of 100px and a max of whatever it requires.

    I must say CSS has advanced a lot to make easier programmers lives.

    0 讨论(0)
  • 2020-12-04 11:54

        html,
        body {
            height: 100%;
        }
    
        .parent {
            display: flex;
            flex-flow:column;
            height: 100%;
            background: white;
        }
    
        .child-top {
            flex: 0 1 auto;
            background: pink;
        }
    
        .child-bottom {
            flex: 1 1 auto;
            background: green;
        }
        <div class="parent">
            <div class="child-top">
              This child has just a bit of content
            </div>
            <div class="child-bottom">
              And this one fills the rest
            </div>
        </div>

    0 讨论(0)
提交回复
热议问题