03
Apr

Stick footer to bottom CSS tip


At the moment I’m working on a new design for another site I’ve made.
And because of the design I’ve made for that site, the footer had to stick to the bottom all the time.
You can do it with javascript, but here’s a way to do it with some simple CSS.
To do this, you have to make sure you’ll have the following structure within your “body” tags.

open div container
  div header
  div content
  div footer
close div header

The CSS file looks like this:
html,body {
margin:0 auto; /* to center align */
width:960px;
padding:0;
height:100%; /*Required*/
}

#container {
min-height:100%; /*Required*/
position:relative; /*Required*/
}

#header {
background:#fff;
}

#content {
padding:15px;
padding-bottom:60px; /*Required, Height of the footer */
}

#footer {
position:absolute;
bottom:0; /*Required*/
width:100%;
height:55px; /*Required, Height of the footer */
}

What does this do?
Firstly we give the html and body tags a height of 100%.
Then we make sure the container that encapsulates any other div has a minimum height of 100% and we give it a relative position.
Because of the relative position of the container we can put something in it with an absolute position, like the footer in this example.
Give the footer a ‘bottom:0’ to stick it to the bottom of the relative position.
Define the height of the footer and also define it in the ‘content’ tag with the use of ‘padding-bottom’. Set it at the same height as your footer-height.

Voila, that’s it.

Now you can put all the stuff you want between your content div without the worry that your footer isn’t positioned right. It will stick to the bottom. Try it by resizing your window.

Hopefully this tip it will be of any use. smile



If you're new here or if you like this post, you may want to subscribe to my RSS feed or get your blog updates by email . You can also find out what I'm doing right now by following me on Twitter. Thanks for visiting!



5 Responses to "Stick footer to bottom CSS tip"


Posted by Franca Richard  on  Apr 05  at  04:34 PM

Really useful I ll test it coz I am learning css these days, the codes are so attractive! Thanks!

Posted by Alex  on  Apr 12  at  06:24 AM

Why you want to make it stuck at footer. i dont understood but the footer is always at bottom.

Posted by Hanne  on  May 05  at  10:10 PM

Great site. Good info.
I am from Belize and too poorly know English, give true I wrote the following sentence: “Cheap airline tickets, travel bargains, air plane last minute tickets and other travel bargains online.”

Thank you so much for your future answers smile.  Hanne.

Posted by Joomla CSS Expert  on  Jun 01  at  02:25 PM

Thank you for the solution. I have tried some techniques but yours looks to be more flexible than the others.

I was wondering how your solution is gonna work if the footer has dynamic height. In this case we don’t know the height of the footer and therefore the padding-bottom is unknown for the containing div.

Posted by Zeb  on  Nov 03  at  07:09 AM

Tried a few other solutions and nothing worked until i found this one.. Thanks a lot


Leave A reply

Name:
  (required)

Email:
  (will not be published) (required)

My website:

Leave your comment here

Remember my personal information

Submit the word you see below:


Full RSS Feed

Site Sponsors

Follow me on Twitter Play Online Poker

    Featured Sites

    Poker Quiz

    Categories

    Top Commentators

    Most recent entries

    Last comments

    Most Popular

    Monthly Archives


    © 2012 www.the1milliondollarchallenge.com Design by Million Dollar Challenge