How to keep footers at the bottom of the browser window (a.k.a. viewport)

by Hazem 21. October 2009 17:30

I tried many solutions I found during my search on the web (google/bing) nothing worked as for me except the following solution (from http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page).

When an HTML page contains a small amount of content, the footer can sometimes sit halfway up the page leaving a blank space underneath. This can look bad, particularly on a large screen. Web designers are often asked to push footers down to the bottom of the viewport, but it's not immediately obvious how this can be done.

bottom-footer-the-problem

When I first ditched tables for pure CSS layouts I tried to make the footer stay at the bottom but I just couldn't do it. Now, after a few years of practice I have finally figured out a neat way to do it. My method uses 100% valid CSS and it works in all standards compliant browsers. It also fails gracefully with older browsers so it's safe to use on any website.

See it in action: View my demo with the footer at the bottom

The main features

  • Works in all modern, standards compliant browsers

    Compatible browsers: Firefox (Mac & PC), Safari (Mac & PC), Internet Explorer 7, 6 & 5.5, Opera and Netscape 8

  • Fails gracefully on older browsers

    Older non-standards compliant browsers position the footer under the content as per normal. We can't help it if people are using an out of date browser, all we can do is reward people who have upgraded by giving them a better browsing experience through progressive enhancement.

  • Longer content pushes the footer off the page

    On long pages with lots of content the footer is pushed off the visible page to the very bottom. Just like a normal website, it will come into view when you scroll all the way down. This means that the footer isn’t always taking up precious reading space.

  • 100% valid CSS with no hacks

    The CSS used in this demo is 100% valid and contains no hacks.

  • No JavaScript

    JavaScript is not necessary because it works with pure CSS.

  • iPhone compatible

    This method also works on the iPhone and iPod Touch in the mobile Safari browser.

  • Free to download

    Simply save the source code of my demo page and use it however you like.

There is only one limitation

You must set the height of the footer div to something other than auto. Choose any height you like, but make sure the value is specified in pixels or ems within your CSS. This is not a big limitation, but it is essential for this method to work correctly.

If you have a lot of text in your footer then it's also a good idea to give the text a bit more room at the bottom by making your footer a bit deeper. This is to cater for people who have their browser set to a larger text size by default. Another way to solve the same problem is to set the height of the footer in em units; this will ensure that the footer grows in size along with the text. If you only have images in your footer than there's nothing to worry about – just set your footer height to a pixel value and away you go.

So how does it work?

It's actually not that complicated. There are two parts to it - the HTML and the CSS.

The HTML div structure

<div id="container">
   <div id="header"></div>
   <div id="body"></div>
   <div id="footer"></div>
</div>

There are only four divs required for this to work. The first is a container div that surrounds everything. Inside that are three more divs; a header, a body and a footer. That's it, all the magic happens in the CSS.

The CSS

html,
body {
   margin:0;
   padding:0;
   height:100%;
}
#container {
   min-height:100%;
   position:relative;
}
#header {
   background:#ff0;
   padding:10px;
}
#body {
   padding:10px;
   padding-bottom:60px;   /* Height of the footer */
}
#footer {
   position:absolute;
   bottom:0;
   width:100%;
   height:60px;   /* Height of the footer */
   background:#6cf;
}

And one simple CSS rule for IE 6 and 5.5:

#container {
   height:100%;
}

The html and body tags

The html and body tags must be set to height:100%; this allows us to set a percentage height on our container div later. I have also removed the margins and padding on the body tag so there are no spaces around the parameter of the page.

The container div

The container div has a min-height:100%; this will ensure it stays the full height of the screen even if there is hardly any content. Many older browsers don't support the min-height property, there are ways around it with JavaScript and other methods but that is out of scope for this article. The container div is also set to position:relative; this allows us to absolutely position elements inside it later.

The header div

There is nothing unusual with the header. Make it whatever colour and size you like.

The body div

The body is quite normal too. The only important thing is it must have a bottom padding that is equal to (or slightly larger than) the height of the footer. You can also use a bottom border if you prefer but a margin won't work.

The footer div

The footer has a set height in pixels (or ems). The div is absolutely positioned bottom:0; this moves it to the bottom of the container div. When there is little content on the page the container div is exactly the height of the browser viewport (because of the min-height:100%;) and the footer sits neatly at the bottom of the screen. When there is more than a page of content the container div becomes larger and extends down below the bottom of the viewport - the footer is still positioned at the bottom of the container div but this time you need to scroll down to the end of the page to see it. The footer is also set to width:100%; so it stretches across the whole page.

The IE 6 & 5.5 CSS

Older versions of Internet Explorer don't understand the min-height property but lucky for us the normal height property behaves exactly the same way in these old Microsoft browsers, that is, it will stretch to 100% height of the viewport but if the content is longer it will stretch even further. We simply expose this 100% height rule to Internet Explorer only by using IE conditional comments. View the source on the demo to see how this is done.

So there you have it... A simple, valid way to make the footer get down! I hope you find it useful.

(Source http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page)

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

Make the Footer Stick to the Bottom of a Page | Tutorial | How to

by Hazem 21. October 2009 10:42

 

Make the Footer Stick to the Bottom of a Page

Browsers
Many of us don’t know how to make the sticky footer at the bottom of page using CSS stylesheet.
Now is the time to learn it !

There are several ways to make a footer stick to the bottom of a page using CSS which works on all the major browsers; Internet Explorer 5 and up, Firefox, Safari, Opera and others.

How to use this footer on your website

Add the following lines of CSS to your stylesheet. The negative value for the margin in #wrapper is the same number as the height of #footer and .push. The negative margin should always equal to the full height of the footer (including any padding or borders you may add).
Step 1:
Copy down this code to any text file and save it as “style.css”

* {
margin: 0;
}
html, body {
height: 100%;
}
#wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
#footer, .blank {
height: 4em;
}

Step 2:

Now use this HTML Structure. Nothing should be outside of the #wrapper and #footer div tags unless it is absolutely positioned with CSS StyleSheet.
Copy down this code to a new text file and save it as “index.html”

<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="wrapper">
<p>Your Content here.</p>
<div class=”blank”></div>
</div>
<div id=”footer”>
<p>Copyright (c) 2008 Pegor.com</p>
</div>
</body>
</html>

Make the Footer Stick to the Bottom of a Page | Tutorial | How to

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

swfIR: swf Image Replacement

by Hazem 16. October 2009 09:48

swfir_logo[1]swfIR (swf Image Replacement) is here to solve some of the design limitations of the standard HTML image and its widely-accepted associated CSS values, while still supporting standards-based design concepts. Using the dark arts of JavaScript and Flash, swfIR gives you the ability to apply an assortment of visual effects to any or all images on your website. Through progressive enhancement, it looks through your page and can easily add some new flavor to standard image styling.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

Steven Hargrove : How to redirect a web page, the smart way

by Hazem 14. October 2009 21:58

Tags:

From Print to the Web: A Designer's Guide - New Media Campaigns

by Hazem 14. October 2009 21:09

 

Typography for the Web

Web Safe Fonts

Typography on the web is depressing. There is really no way around it. There are some emerging technologies that could make the situation better, but these are the only safe fonts for copy:

  • Times / Times New Roman
  • Georgia
  • Palatino Linotype
  • Andale Mono
  • Arial
  • Arial Black
  • Impact
  • Trebuchet MS
  • Verdana
  • Comic Sans MS
  • Courier New

So what does "web-safe" mean? It means you can expect them to be installed on a visitor's computer and that it will render as you expect. If you use a font that a visitor doesn't have, the results cannot necessarily be anticipated and a replacement font will be selected. To try out some of these fonts on the fly, the following tool is great:


Using Non-Web-Safe Fonts

Other fonts can also be used sparingly by using a number of techniques. The thing to remember, however, is that any of these techniques have downsides. They either cause the page to render more slowly, increase the file-size of the site, or make text impossible to copy and paste. Many of the best "web-medium" designs stick to web-safe fonts as much as possible

Replacement Techniques:

  • Basic Image Replacement - This is just a rasterizaton of the text to a static jpg, gif or png. This makes it impossible to update the text with a CMS and also can have some SEO downsides. This is the best technique for logos or other major design elements.
  • Cufon - This uses javascript to draw the text in a font as vector shapes. It is reasonably lightweight and it is easy to change text since it is done dynamically. As a downside, the text cannot be selected and it can have a delay prior to rendering.
  • sIFR - This method is like cufon except it uses flash to render the text. This makes it a little more heavy-weight, but its text can be selected.
Designing for more than Lorem Ipsum

If you are designing a site with client or user generated text, you'll need to consider more than just paragraph text. A good web-style guide will be ready for:

  • Headings 1-6
  • Paragraph Text
  • Ordered Lists
  • Unordered Lists
  • Blockquotes

Building this out will ensure that the site design will continue to look good even as content is added.

From Print to the Web: A Designer's Guide - New Media Campaigns

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

Web Installer Platform

by Hazem 14. October 2009 17:50

A package containing all needed software to develop sites on IIS

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: