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 Record CPU and Memory Usage Over Time in Windows?

Whenever the computer is lagging or some application is taking too long to respond, we usually fire up task manager and look under the Performance tab or under Processes to check on processor utilization or the amount of free memory available. The task manager is ideal for real-time analysis of CPU and memory utilization. It even displays a short history of CPU utilization in the form of a graph. You get a small time-window, about 30 seconds or so, depending on how large the viewing area is.

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.

Diagram 101: Different Types of Diagrams and When To Use Them

Diagrams are a great way to visualize information and convey meaning. The problem is that there’s too many different types of diagrams, so it can be hard to know which ones you should use in any given situation. To help you out, we’ve created this diagram that lays out the 7 most common types of diagrams and when they’re best used: