Zymic

Webmaster resources

Follow us on Twitter!

Hosting status updates - Click here

CSS & HTML

Free Tutorials » CSS & HTML » Effective Footers

Code a footer which sticks to the bottom of the page except when content pushes it down.

Step 1

Having the right footer is important in a website, it can be a large part of the look of the page. In this tutorial we will be covering how to make a fixed-height footer, which sticks to the bottom of the page except when content pushes it down using purely HTML and CSS. You can see an example of this here. This is not entirely trivial because position: absolute; or fixed; would not move down when the page was filled with content, and merely placing it at the bottom of the markup would not ensure it was at the bottom of the page when there was not much content. The solution to the problem is that we make everything but the footer altogether have a minimum height of 100%, then we use a negative top margin on the footer equal to its total height to bring it up, placing the bottom of the footer at the bottom of the page when the content doesn't have a height larger than 100%, perfect! The HTML required for this is fairly simple, something like this will suffice:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Footer Example</title>
</head>
<body>
   <!-- Container Divs -->
   <div id="container"><div id="padding">
      <!-- Header -->
      <h1>Header</h1>
 
      <!-- Content -->
      <h2>Example Content</h2>
      <p>
         Some content...
      </p>
   </div></div>
 
   <!-- Footer -->
   <p id="footer">
      Page Footer
   </p>
</body>
</html>

You can view what this code (with some basic styling to make things clearer) look like here.

Step 2

Now we can start styling the document to get the footer how we want it. First of all, we need to make the container div have a min-height of 100%, this can be achieved in most browsers with the following CSS:

html, body
{
   height: 100%;
   margin: 0;
   padding: 0;
}
div#container
{
   min-height: 100%;
}

Both html and body need to be set to 100% height so that the container div can take up the space. This does the job in a lot of browsers, but unfortunately IE doesn't understand min-height, for some reason IE's height is equivalent to min-height and min-height does not exist, so to combat this we need to set height: 100%; in IE without affecting compliant browsers. We can achieve this using !important in the CSS like so:

div#container
{
   height: auto !important;
   height: 100%;
   min-height: 100%;
}

The !important makes compliant browsers use height: auto; instead of height: 100%; while IE uses height: 100%; instead, fixing it nicely. Our layout now looks like this, almost done!

Step 3

Now that our main content area is formatted correctly we can turn our attention to the footer. At the moment it is just below the main content, so we need to apply our negative top margin to pull it up into the correct position. To do this, first we need to calculate its total height, in this case we have made the footer 17px in height, with an additional 9px padding at the top, and another 9px at the bottom. Therefore, the total height of the footer is 17+9+9 = 35px. So we need to move the footer 35 pixels up, which is done with this line:

p#footer
{
   margin: -35px 0 0 0;
   /* ... other styles ... */
}

This makes the top margin negative 35 and sets left, right and bottom to 0. Now, this is now perfect when there is little content, but when more is introduced to the page we see a problem emerge, the content overflows onto the footer which is hardly something we want. We fix this using the "padding" div that was introduced in the HTML at the beginning, we can't use padding on the container div, because that would make the height of the container div 100%+padding, and would push the footer below the bottom of the page again, so instead we have to pad another container inside the first, in this case the "padding" div. The fix is very simple, and is simply this:

div#padding { padding: 0 0 45px 0; }

Once this is in place, content no longer overflows onto the footer when there's a lot of it, and when there is little the page is unaffected.

Step 4

That's pretty much that on making footers like this, it's a useful tool and widely compatible, this method has been tested on:

  • IE 5
  • IE 5.5
  • IE 6
  • IE 7
  • Firefox 2
  • Opera 9
  • Konqueror 3.5.7
  • Safari 2.0.4
NOTE: IE5 and 5.5 don't play well with the dynamic example at the top of the page, but are fine with static pages.

Tutorial comments

16.09.2014 -

polo2014 says …



http://www.shopbestgoods.com/
http://www.nike-jordanshoes.com/
http://www.beatsbydreoutlet.net/
http://www.michaelkorsus.com/
http://www.polo-tshirts.com/
http://www.northsclearance.com/
http://www.ralph-laurensale.com/
http://www.gucci-shoesuk2014.com/
http://www.michael-korsusa.com/
http://www.polo-outlets.com/
http://www.ralph-laurenhome.com/
http://www.marcjacobsonsale.com/
http://www.mcmworldwides.com/
http://www.salongchamppairs.com/
http://www.canada-gooser.com/
http://www.burberryoutlet2014.com/
http://www.michaelkors.so/
http://www.hermes-outletonline.com/
http://www.oakley-sunglassoutlet.com/
http://www.north-faceoutlets.net/
http://www.moncler-clearance.com/
http://www.woolrich-clearance.com/
http://www.barbour-jacketsoutlet.com/
http://www.moncler-jacketsoutletonline.com/
http://www.monsterbeatsbydres.net/
http://www.louis-vuittonblackfriday.com/
http://www.lv-guccishoesfactory.com/
http://www.mcmoutlet-jp.com/
http://www.cheapdiscountoutlet.com/
http://coachoutlet.iwopop.com/
http://www.coachsfactoryoutlet.com/
http://www.coach-blackfriday2014.com/
http://www.coach-storeoutletonline.com/
http://www.coach-factorysoutletonline.com/
http://www.coachccoachoutlet.com/
http://www.coach-factories.net/
http://www.coach-pursesoutletonline.com/
http://www.llouisvuitton-factory.net/
http://www.coach-outletsusa.com/
http://www.mksfactoryoutlet.com/
http://www.zxcoachoutlet.com/
http://www.mischristmas.com/
http://www.misblackfriday.com/
http://www.bestcustomsonline.com/
http://www.newoutletonlinemall.com/
http://www.clickmichaelkors.com/
http://www.cmichaelkorsoutlet.com/
http://www.ralphlaurenepolo.com/
http://michaelkorsoutlet.mischristmas.com/
http://mcmbackpack.mischristmas.com/
http://monsterbeats.mischristmas.com/
http://northfaceoutlet.mischristmas.com/
http://mk.misblackfriday.com/
http://coachoutlet.misblackfriday.com/
http://coachfactory.misblackfriday.com/
http://uggaustralia.misblackfriday.com/
http://coachpurses.misblackfriday.com/
http://coachusa.misblackfriday.com/
http://coach.misblackfriday.com/
http://michaelkorss.misblackfriday.com/
http://michaelkors.misblackfriday.com/
http://airmax.misblackfriday.com/
http://michael-kors.misblackfriday.com/
https://www.facebook.com/pages/Coach-Factory-Outlet-Online-Store-Michael-Kors-Outlet-Online-Sale-75-Off/712060898859091
https://www.facebook.com/pages/Ralph-Lauren-Polo-Outlet-Online-Sale/1404100279810690

16.09.2014 -

polo2014 says …

http://www.shopbestgoods.com/
http://www.nike-jordanshoes.com/
http://www.beatsbydreoutlet.net/
http://www.michaelkorsus.com/
http://www.polo-tshirts.com/
http://www.northsclearance.com/
http://www.ralph-laurensale.com/
http://www.gucci-shoesuk2014.com/
http://www.michael-korsusa.com/
http://www.polo-outlets.com/
http://www.ralph-laurenhome.com/
http://www.marcjacobsonsale.com/
http://www.mcmworldwides.com/
http://www.salongchamppairs.com/
http://www.canada-gooser.com/
http://www.burberryoutlet2014.com/
http://www.michaelkors.so/
http://www.hermes-outletonline.com/
http://www.oakley-sunglassfactory.com/
http://www.north-faceoutlets.net/
http://www.moncler-clearance.com/
http://www.woolrich-clearance.com/
http://www.barbour-jacketsoutlet.com/
http://www.moncler-jacketsoutletonline.com/
http://www.monsterbeatsbydres.net/
http://www.louis-vuittonblackfriday.com/
http://www.lv-guccishoesfactory.com/
http://www.mcmoutlet-jp.com/
http://www.cheapdiscountoutlet.com/
http://coachoutlet.iwopop.com/
http://www.coachsfactoryoutlet.com/
http://www.coach-blackfriday2014.com/
http://www.coach-storeoutletonline.com/
http://www.coach-factorysoutletonline.com/
http://www.coachccoachoutlet.com/
http://www.coach-factories.net/
http://www.coach-pursesoutletonline.com/
http://www.llouisvuitton-factory.net/
http://www.coach-outletsusa.com/
http://www.mksfactoryoutlet.com/
http://www.zxcoachoutlet.com/
http://www.mischristmas.com/
http://www.misblackfriday.com/
http://www.bestcustomsonline.com/
http://www.newoutletonlinemall.com/
http://www.clickmichaelkors.com/
http://www.cmichaelkorsoutlet.com/
http://www.ralphlaurenepolo.com/
http://michaelkorsoutlet.mischristmas.com/
http://mcmbackpack.mischristmas.com/
http://monsterbeats.mischristmas.com/
http://northfaceoutlet.mischristmas.com/
http://mk.misblackfriday.com/
http://coachoutlet.misblackfriday.com/
http://coachfactory.misblackfriday.com/
http://uggaustralia.misblackfriday.com/
http://coachpurses.misblackfriday.com/
http://coachusa.misblackfriday.com/
http://coach.misblackfriday.com/
http://michaelkorss.misblackfriday.com/
http://michaelkors.misblackfriday.com/
http://airmax.misblackfriday.com/
http://michael-kors.misblackfriday.com/
https://www.facebook.com/pages/Coach-Factory-Outlet-Online-Store-Michael-Kors-Outlet-Online-Sale-75-Off/712060898859091
https://www.facebook.com/pages/Ralph-Lauren-Polo-Outlet-Online-Sale/1404100279810690

04.09.2014 -

godisagirl says …

http://www.coachoutletstoreinuk.com Coach Factory Outlet
http://www.coachfactoryoutletanus.com Coach Factory Outlet
http://www.coachoutletonlineunsius.com Coach Outlet
http://www.coachoutletonlinetur.com Coach Online Outlet
http://www.coachfactoryoutletnbsa.com Coach Factory Outlet
http://www.coachfactoryoutletuisa.com Coach Outlet Store
http://www.coachoutletstorenie.com Coach Outlet Store
http://www.coachfactorystoreuin.com Coach Outlet Online
http://www.coachfactoryoutletreba.com Coach Factory Outlet
http://www.coachfactoryoutletonlinesius.com Coach Factory Online
http://www.coachoutletonlinetnse.com Coach Factory Outlet
http://www.coachoutletnoia.com Coach Outlet Store Online
http://www.chaneloutletinaus.com Chanel Handbags
http://www.louisvuittonoutletina.com Louis Vuitton Outlet Online
http://www.louisvuittonoutletine.com Louis Vuitton Outlet
http://www.guccibeltsoutletbcus.com Louis Vuitton Belt
http://www.guccibelststco.com Hermes Belt
http://www.coachoutletstoreinuk.com Coach Outlet Online
http://www.coachfactoryoutletanus.com Coach Outlet
http://www.coachoutletonlineunsius.com Coach Factory Outlet
http://www.coachoutletonlinetur.com Coach Outlet Online
http://www.coachfactoryoutletnbsa.com Coach Factory Outlet
http://www.coachfactoryoutletuisa.com Coach Outlet Store Online
http://www.coachoutletstorenie.com Coach Outlet Store Online
http://www.coachfactorystoreuin.com Coach Factory Outlet
http://www.coachfactoryoutletreba.com Coach Outlet
http://www.coachfactoryoutletonlinesius.com Coach Handbags Outlet
http://www.coachoutletonlinetnse.com Coach Outlet
http://www.coachoutletnoia.com Coach Outlet
http://www.chaneloutletinaus.com Chanel Outlet Online
http://www.louisvuittonoutletina.com Louis Vuitton
http://www.louisvuittonoutletine.com Louis Vuitton Outlet
http://www.guccibeltsoutletbcus.com Gucci Belts
http://www.guccibelststco.com Gucci Belt
http://www.louisvuittonoutletsnib.com Louis Vuitton Outlet Online
http://www.oakleysunglassescnc.name Oakley Sunglasses Outlet
http://www.louisvuittonoutletmoba.com Louis Vuitton Outlet Online
http://www.oakleyssunglassesmobo.com Oakley Sunglasses Outlet
http://www.oakleysunglassesmaba.com Cheap Oakley Sunglasses
http://www.oakleysunglassinsc.com Oakley Sunglasses
http://www.louisvuittonoutletsnib.com Louis Vuitton Outlet
http://www.oakleysunglassescnc.name Oakley Sunglasses Outlet
http://www.louisvuittonoutletmoba.com Louis Vuitton Outlet
http://www.oakleyssunglassesmobo.com Oakley Sunglasses Outlet
http://www.oakleysunglassesmaba.com Oakley Sunglasses
http://www.oakleysunglassinsc.com Oakley Sunglasses

22.07.2014 -

Sameershokat says …

Hi there;!
actually i am new member and i just join that forum now so i have no any idea about there you asking question so i am also interested something about know that and i hope there are all guy,s helped me & increased my knowledge well so i am waiting here buddies for your exciting comments .....!

05.05.2014 -

teamns says …

Shame about the spammers in this post

View all user comments for this tutorial.

Tutorial statistics

Date added:
25.08.2007
Author:
Alex Elliott
User rating:
4/5
Rate tutorial:
Total views:
92405
Total comments:
460

Advertisements