I have a header element and a content element:
#header
#content
I want the header to be of fixed height and the content to fill up all the
Very simple:
#content {
max-height: 100%;
}
forget all the answers, this line of CSS worked for me in 2 seconds :
height:100vh;
1vh
= 1% of browser screen height
source
For responsive layout scaling, you might want to use :
min-height: 100vh
[update november 2018] As mentionned in the comments, using the min-height might avoid having issues on reponsive designs
[update april 2018] As mentioned in the comments, back in 2011 when the question was asked, not all browsers supported the viewport units.
The other answers were the solutions back then -- vmax
is still not supported in IE, so this might not be the best solution for all yet.
Unless you need to support IE 9 and below, I would use flexbox
body { display: flex; flex-direction: column; }
.header { height: 70px; }
.content { flex: 1 1 0 }
You also need to get body to fill the whole page
body, html{ width:100%; height:100%; padding: 0; margin: 0;}
The best solution I found so far is setting a footer element at the bottom of the page and then evaluate the difference of the offset of the footer and the element we need to expand. e.g.
<div id="contents"></div>
<div id="footer"></div>
#footer {
position: fixed;
bottom: 0;
width: 100%;
}
var contents = $('#contents');
var footer = $('#footer');
contents.css('height', (footer.offset().top - contents.offset().top) + 'px');
You might also like to update the height of the contents element on each window resize, so...
$(window).on('resize', function() {
contents.css('height', (footer.offset().top -contents.offset().top) + 'px');
});
#Header
{
width: 960px;
height: 150px;
}
#Content
{
min-height:100vh;
height: 100%;
width: 960px;
}