Skip to main content

How to make the footer stick to the bottom of a page

The footer on a web page begins where the main page content ends. Unlike the page header which always sticks to the top of the page irrespective of the page size, the position of the footer depends on the amount of content the page carries.

While this is no problem for pages with lots of content, but when a page doesn’t have enough content to cover the entire height of the monitor screen the footer doesn’t appear exactly at the foot of the page. It appears just where the page content ends, often midway. This looks bad from a design perspective.

floating-footer

One solution to this problem is to apply a “Sticky Footer” code. There are many sticky footer hacks but most of them are old and fails on newer browsers. The following solution proposed by CSSStickyFooter.com has been reportedly tested on over 50 browsers.

In a typical page structure the footer element sits inside the page wrapper. In this sticky footer code, the footer <div> sits outside of the wrap <div> like this.

<div id="wrap"> 
             <div id="main"> 
             </div>
</div>

<div id="footer">
</div>

If your page has the footer inside the wrap element, have it moved outside it as shown.

Now add the following code to the stylesheet.

html, body, #wrap {height: 100%;}

body > #wrap {height: auto; min-height: 100%;}

#main {overflow:auto;
    padding-bottom: 150px;}  /* must be same height as the footer */

#footer {position: relative;
    margin-top: -150px; /* negative value of footer height */
    height: 150px;
    clear:both;}

/*Opera Fix*/
body:before {
    content:"";
    height:100%;
    float:left;
    width:0;
    margin-top:-32767px;/
}

And on your html page you will need this conditional, primarily for IE8;

<!--[if  IE 8]>
    <style type="text/css">
        #wrap {display:table;}
    </style>
<![endif]—>

Test your page in a browser – the footer should rest at the bottom of the page.

For explanation and known issues, read this.

Comments

Popular posts from this blog

How to Schedule Changes to Your Facebook Page Cover Photo

Facebook’s current layout, the so called Timeline, features a prominent, large cover photo that some people are using in a lot of different creative ways. Timeline is also available for Facebook Pages that people can use to promote their website or business or event. Although you can change the cover photo as often as you like, it’s meant to be static – something which you design and leave it for at least a few weeks or months like a redesigned website. However, there are times when you may want to change the cover photo frequently and periodically to match event dates or some special promotion that you are running or plan to run. So, here is how you can do that.

69 alternatives to the default Facebook profile picture

If you have changed the default Facebook profile picture and uploaded your own, it’s fine. But if not, then why not replace that boring picture of the guy with a wisp of hair sticking out of his head with something different and funny?

How to remove watermark from an image or picture

A watermark is any recognizable text, logo or pattern that appears over an image to identify the owner of the image and generally used to prevent unauthorized reuse of the image. Watermarks are usually transparent and can be difficult to remove. The difficulty or ease of removal depends on the content of the image and the position, color, size etc of the watermark.