Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:00:23+00:00 2026-06-06T11:00:23+00:00

Consider the following HTML/css code sample: <div id="container"> <div id="up">Text<br />Text<br />Text<br /></div> <div

  • 0

Consider the following HTML/css code sample:

<div id="container">
    <div id="up">Text<br />Text<br />Text<br /></div>
    <div id="down">Text<br />Text<br />Text<br /></div>
</div>
#container { width: 300px; height: 300px; border:1px solid red;}
#up { background: green; }
#down { background:pink;}

where I have a container div with two children (also here: http://jsfiddle.net/S8g4E/). The first child has a given height. How can I make the second child to occupy the "free space" of the container div without giving a specific height?

In the example, the pink div should occupy also the white space.


Similar to this question: How to make div occupy remaining height?

But I don’t want to give position absolute.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:00:25+00:00Added an answer on June 6, 2026 at 11:00 am

    Expanding the #down child to fill the remaining space of #container can be accomplished in various ways depending on the browser support you wish to achieve and whether or not #up has a defined height.

    Note (2024): CSS now has max-content property value for sizing as well, so if you don’t have a fixed height (e.g. 100px) then you might be able to use that.

    Samples

    .container {
      width: 100px;
      height: 300px;
      border: 1px solid red;
      float: left;
    }
    .up {
      background: green;
    }
    .down {
      background: pink;
    }
    .grid.container {
      display: grid;
      grid-template-rows: 100px;
    }
    .flexbox.container {
      display: flex;
      flex-direction: column;
    }
    .flexbox.container .down {
      flex-grow: 1;
    }
    .calc .up {
      height: 100px;
    }
    .calc .down {
      height: calc(100% - 100px);
    }
    .overflow.container {
      overflow: hidden;
    }
    .overflow .down {
      height: 100%;
    }
    <div class="grid container">
      <div class="up">grid
        <br />grid
        <br />grid
        <br />
      </div>
      <div class="down">grid
        <br />grid
        <br />grid
        <br />
      </div>
    </div>
    <div class="flexbox container">
      <div class="up">flexbox
        <br />flexbox
        <br />flexbox
        <br />
      </div>
      <div class="down">flexbox
        <br />flexbox
        <br />flexbox
        <br />
      </div>
    </div>
    <div class="calc container">
      <div class="up">calc
        <br />calc
        <br />calc
        <br />
      </div>
      <div class="down">calc
        <br />calc
        <br />calc
        <br />
      </div>
    </div>
    <div class="overflow container">
      <div class="up">overflow
        <br />overflow
        <br />overflow
        <br />
      </div>
      <div class="down">overflow
        <br />overflow
        <br />overflow
        <br />
      </div>
    </div>

    Grid

    CSS’s grid layout offers yet another option, though it may not be as straightforward as the Flexbox model. However, it only requires styling the container element:

    .container { display: grid; grid-template-rows: 100px }
    

    The grid-template-rows defines the first row as a fixed 100px height, and the remain rows will automatically stretch to fill the remaining space.

    I’m pretty sure IE11 requires -ms- prefixes, so make sure to validate the functionality in the browsers you wish to support.

    Flexbox

    CSS3’s Flexible Box Layout Module (flexbox) is now well-supported and can be very easy to implement. Because it is flexible, it even works when #up does not have a defined height.

    #container { display: flex; flex-direction: column; }
    #down { flex-grow: 1; }
    

    It’s important to note that IE10 & IE11 support for some flexbox properties can be buggy, and IE9 or below has no support at all.

    Calculated Height

    Another easy solution is to use the CSS3 calc functional unit, as Alvaro points out in his answer, but it requires the height of the first child to be a known value:

    #up { height: 100px; }
    #down { height: calc( 100% - 100px ); }
    

    It is pretty widely supported, with the only notable exceptions being <= IE8 or Safari 5 (no support) and IE9 (partial support). Some other issues include using calc in conjunction with transform or box-shadow, so be sure to test in multiple browsers if that is of concern to you.

    Other Alternatives

    If older support is needed, you could add height:100%; to #down will make the pink div full height, with one caveat. It will cause overflow for the container, because #up is pushing it down.

    Therefore, you could add overflow: hidden; to the container to fix that.

    Alternatively, if the height of #up is fixed, you could position it absolutely within the container, and add a padding-top to #down.

    And, yet another option would be to use a table display:

    #container { width: 300px; height: 300px; border: 1px solid red; display: table;}
    #up { background: green; display: table-row; height: 0; }
    #down { background: pink; display: table-row;}​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code : HTML: <div> <label for='name'>Name:</label> <input type='text' id='name' /> </div>
Consider the following code HTML: <span class='c1'>Home<sup id='id1'>[2]</sup></span> CSS: .c1 { text-decoration:underline; } #id1
Consider the following code : HTML: <div id='button' class='enabled'>Press here</div> <div id='log'></div> CSS: #button
Consider the following code : HTML: <div class='a'></div> <div class='b'></div> CSS: body { position:
Consider the following html code: <div id='x'><div id='y'>Y content</div>X content</div> I'd like to extract
Consider the following html snippet <!DOCTYPE html> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.4.2.js ></script> <script
Let's consider following html code: <p> Some text followed by <span>a span element</span> and
Consider the following code : HTML: <div id=wrapper> <div class='a'></div> <div class='a'></div> <div class='a'></div>
Consider the following example : HTML: <div class=wrapper> <div class=left>Some text here</div><div class=right>Hello Stack
Consider the following example: ( live demo ) HTML: <div>div</div> <iframe></iframe> CSS: div, iframe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.