Jump to content

Body with 100% height only filling the viewport, not the page


bare_nature

Recommended Posts

Hello,

 

I have read several posts about this on this forum and other fora, but I don't see any solutions. The question is dead simple, why is it that when the body is assigned a height of 100% that it only fills the viewport and not 100% of the page?

 

First of all, I don't see any use for this and second, it is illogical.

 

Are there fixes for this? It would make my day if one of you CSS experts would give a straightforward answer to this question.

 

Thanks a lot!

 

Bart

Link to comment
Share on other sites

Setting an element to a height of 100% means it completely fills the height of it's parent element. You are probably thinking of the body as the top parent in the page, but actually the HTML tag is the top parent in the page. So you need to set both the HTML tag and the body tag to be 100%.

 

html, body
{
  height:100%;
}

 

Try that out.

Link to comment
Share on other sites

Well, I have been trying to create a layout for days now, but had to give it up. Normally I am stubborn like hell, but the deadline wins it this time.

 

I wanted to create a layout like that of Smashing Magazine, that is, full width header, full width footer, but the footer needs to stay at the bottom of the page at all times. If the content is not filling the whole page then the footer must remain at the bottom of the page.

 

The problem I ran into was that the body (height: 100%) only took up the viewport (not the entire page) when the main content was larger than the viewport. The consequence was that my footer (given an absolute position at the bottom) also stayed at the bottom of the viewport and not the full page (which resulted in a strange effect).

 

If I would use float: left and clear: both for the footer, then it wouldn't stay at the bottom if the content does not fill the entire page.

 

I hope you get the idea. I started this thread as a last resort, but don't expect to find a definitive answer. I'm just baffled that I couldn't find the solution  :shrug:.

 

Thanks for your time anyway. It is much appreciated.

 

Bart

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.