Make a Div Stick to the Bottom

May 17, 2011 2 Comments

It’s possible. CSS only. No javascript. No funny-business.

Most of the time I do this for a footer on a website. (See www.weissauctions.com, or our own site even, www.twinharbor.com). The footer should stick to the bottom of the page (or the parent element). If you resize the window and the content doesn’t fill the screen, it should stay down at the bottom. If you need to scroll, it should go out of view. Position:absolute is close but if you have to scroll down, it stays on the bottom rather than moving down where it belongs.

Here’s the elements you need to pull this technique off.

Core html:

<div id="wrapper">
    <div id="content">
        ...put all page content here. anything that should go ABOVE the footer.
    </div>
</div>
<div id="footer">
     Copyright © My Website 2011.
</div>

Minimal CSS:

#wrapper{
min-height:100%;
position:relative;
}

#footer{
clear:both; /* this may not matter if you don't have anything using floats, but it's often quite helpful. */
height: 55px;
margin-top:-55px;
position:relative;
}

#content{
padding-bottom:55px;
}

You can make the height of your footer anything you like, but note that the margin should negate that amount.Also note that you may have to take into account padding or borders and increase that negative margin a bit to compensate. The padding-bottom on the inner content div provides some margin in certain cases to avoid overlap when you shrink the window. I’ve tested this technique in most major browsers and it seems to work well (including IE7!).

I may update this some more…feel free to post your results in the comments!

* Featured, * Featured Lower Section, * News, CSS, Web Design
2 Comments to “Make a Div Stick to the Bottom”
  1. One note – if you find that in some browsers (Safari on mac, and I think Chrome too) that as you resize the window, the footer starts to overlap the content in some situations, watch that you don’t have a height:100% on the wrapper div. Just leaving min-height:100% only on there fixes this one.

  2. lpttiynkao says:

    long year acer trends show only 001 more acelenolysunci topics now pr54 in 2012

Leave a Reply

(required)

(required)


Are you backing up your data?

Most people know they should back up their data, but not everyone does. If you’re one of those people,...

5 Easy Choices For a Better Website.

Are you planning to design or redesign your website soon? If so, then here are a few tips that...

How to enable site maps in Waypoint

Sitemaps are simple XML files that Google and other search engines use to find the content in your website....

5 reasons you should learn how to use HTML

HTML is the backbone of everything online. Everyone should know how to read it and write it! OK, well...

How to Link Facebook to Twitter

Posting to Facebook, LinkedIn, Twitter and other social media sites is a great way to interact with your customers....

Visual Studio Environment Tips

This week I had to send my iMac in for repair. Normally I program using Windows Server 2008 running...

Fixing IIS7 Maximum Upload Size

If you have your Waypoint site hosted with Twin Harbor and you need to increase the maximum file upload...

What is an SSL Certificate?

You may have heard about SSL Certificates, also called secure certificates, or SSL Certs for short. But what are...

OSX Lion Removes Functionality

In my previous post I thought I had found a way to maintain some of the functionality that we...

Assign Applications to “Spaces” in OSX Lion

I was a happy user of Spaces in OSX 10.6 Snow Leopard. You could assign certain applications to certain...