Home arrow HTML arrow Advanced Sticky Footers in HTML and CSS
HTML

Advanced Sticky Footers in HTML and CSS


In this two-part tutorial, I demonstrate how easy it is to create a couple of sticky web page footers by using a combination of clean markup and a few basic CSS styles.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 6
December 26, 2011
TABLE OF CONTENTS:
  1. · Advanced Sticky Footers in HTML and CSS
  2. · HTML AND CSS Absolute Positioning

print this article
SEARCH DEVARTICLES

Advanced Sticky Footers in HTML and CSS
(Page 1 of 2 )

Sticky footers are nothing but “classic” HTML footers, except that they’re always displayed at the bottom of the web page, regardless of whether or not the page’s primary contents occupy the entire browser display window. Got the logic behind this concept? Great.

Though the term “sticky” might seem somewhat intimidating, the truth is that the implementation of this kind of popular footer is much easier than one might think. The entire process only requires that you  define within the markup the footer area itself, and then place it at the bottom of the HTML document by utilizing some basic CSS properties, such as relative/absolute positioning, padding and margins.

Of course, if you've already read the first part of this tutorial, you have a pretty accurate idea of how to drop a sticky footer into a web page. In that installment I explained how to accomplish this by means of the aforementioned CSS properties. The footer created then was positioned outside the page’s main wrapper. There's nothing particularly wrong with that; it’s possible, though, to build a similar footer by placing it inside the corresponding wrapper.

If you’re interested in learning the details of this process, in the lines to come I’ll be showing you how to create a subtle variation of the initial sticky footer of the preceding article, which will be neatly included within the web page’s main wrapper.

Building a Simple (X)HTML Document

As I just said, building a sticky footer that lives inside the boundaries of the main wrapper is a straightforward process, which helps to emphasize the semantic meaning of the containing web page. To demonstrate this, below I defined a basic (X)HTML document, which effectively includes its footer section within the mentioned wrapper. Have a look at it: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Creating a sticky footer with CSS (the footer is placed inside the main wrapper)</title>
</head>
<body>
<div id="wrapper">
    <div id="header">
        <h1>Creating a sticky footer with CSS</h1>
        <h2>Header section</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque rhoncus sodales sapien ac blandit. Nam lacus urna, commodo eget tincidunt vitae, ullamcorper at nulla. Vivamus ac iaculis justo.</p>
   </div>
   <div id="main">
        <h2>Content section</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere ullamcorper lacus et sollicitudin. Morbi ultrices condimentum lacus, sit amet venenatis purus bibendum sit amet. Quisque rhoncus sodales sapien ac blandit. Nam lacus urna, commodo eget tincidunt vitae, ullamcorper at nulla. Vivamus ac iaculis justo.</p>
    </div>
    <div id="footer">   
        <h2>Footer section</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere ullamcorper lacus et sollicitudin. Morbi ultrices condimentum lacus, sit amet venenatis purus bibendum sit amet. Quisque rhoncus sodales sapien ac blandit. Nam lacus urna, commodo eget tincidunt vitae, ullamcorper at nulla. Vivamus ac iaculis justo.</p>
    </div>   
</div>
</body>
</html>

Definitely, the structure of the above web page follows the tenets of modern web design more closely, where the footer section is a descendant of a primary wrapper, which in turn is used as a generic container to create (in many cases), a fixed, centered layout.

With this skeleton already set, the question is whether or not it’s feasible to turn the previous footer into a sticky element which will be displayed at the bottom of the (X)HTML document. Well, in fact it is. And to give you proof of my claim, in the following section I’ll be defining the set of CSS styles that will achieve this.


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials