How to make div occupy remaining height?

user666491 picture user666491 · Aug 26, 2011 · Viewed 99.7k times · Source

I have this problem, I have two divs:

<div style="width:100%; height:50px;" id="div1"></div>
<div style="width:100%;" id="div2"></div>

How do I make div2 occupy remaining height of the page?

Answer

Alexander Rafferty picture Alexander Rafferty · Aug 26, 2011

Use absolute positioning:

#div1{
    width: 100%;
    height: 50px;
    background-color:red;/*Development Only*/
}
#div2{
    width: 100%;
    position: absolute;
    top: 50px;
    bottom: 0;
    background-color:blue;/*Development Only*/
}
<div id="div1"></div>
<div id="div2"></div>