Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make footer height extend to bottom of the page

I have a very simple webpage with a problem. It ahs 3 divs that sit ontop of each other, the header, content then footer.

I want my footers height to expand to the bottom of the page. How can I do this?

The header has a constant height, the content will vary in height depending on the content received from an AJAX call. So I cant explicitly set it.

Heres my JSFiddle: http://jsfiddle.net/5U6ZB/2/embedded/result/

<div id="header"></div>
<div id="content">
    <!-- height is dynamic sometimes it will be full of divs that makes it
         longer than the screen height other times it only has 1 div  -->
</div>
<div id="footer">
    <!-- How do I make the footer height fill up the rest of the page height? -->
</div>

body { background-color: white; }
div  { width: 100%; }

#header {
    height: 400px;
    background-color: RGB(200,200,200);
}

#content {

}

#footer {
    background-color: RGB(112,112,112);
    /*How do I make the footer height fill up the rest of the page height?*/
}
like image 794
sazr Avatar asked Feb 16 '12 01:02

sazr


People also ask

Why is the footer at the bottom of the page?

The footer has a set height in pixels (or ems). The div is absolutely positioned bottom: 0; this moves it to the bottom of the container div. When there is little content on the page the container div is exactly the height of the browser viewport (because of the min-height: 100%;) and the footer sits neatly at the bottom of the screen.

How do I change the distance between the header and footer?

The distance between the edge of the paper and the top of a header and the edge of the page and the bottom of the footer is controlled using File, Page Setup, and the Margins tab. The From Edge Header and Footer settings control this distance. Decreasing them moves the header or footer closer to the page edge and increases the space on the page.

How do I increase the size of the footer?

This is to cater for people who have their browser set to a larger text size by default. Another way to solve the same problem is to set the height of the footer in em units; this will ensure that the footer grows in size along with the text.

What happens if I decrease the size of my header/footer?

Decreasing them moves the header or footer closer to the page edge and increases the space on the page. However, be careful not to decrease this amount too much or your header or footer will no longer print.


3 Answers

html {
background-color:#093; /*the footer color*/
}

body {

background-color: #f6f; /*the body color*/
}
like image 174
steve Avatar answered Oct 10 '22 11:10

steve


Sounds like the easiest solution in your case would be to make the body background the same colour as the footer and make your content white. This would give the illusion of the footer going all the way to the bottom.

body { background-color:RGB(112,112,112); }
div  { width: 100%; } /* Divs are block elements which automatically take 100% width so this is redundant. */

#header {
    height: 400px;
    background-color: RGB(200,200,200);
}

#content {
    background-color:white;
}

#footer {
    background-color: RGB(112,112,112);

}
like image 32
SynXsiS Avatar answered Oct 10 '22 09:10

SynXsiS


:root {
    background-color: siteBackgroundColor;
}

body {
    background-color: footerColor;
}

This doesn't really expand the footer, but visually expands its background color.

like image 38
user3115008 Avatar answered Oct 10 '22 09:10

user3115008