views:

102

answers:

4

My footer is designed to stay at the bottom of the page even if the div above it only has a small amount of content. It worked until recently, and I seem to have broken it somehow. Can you take a look?

Thanks in advance.

CSS:

body {
    margin: 0;
    padding: 0;
    height: 100%;
    font: 100% Helvetica, sans-serif, Arial, sans-serif;
    color: #000;
    background-color: #FFF;
    background-image: url(images/BGmain.png);
    background-repeat: repeat-x;
}
/*----------
Div styles
----------*/
#container {
    min-height: 100%;
    position: relative;
}
.header {
    padding: 0 0 230px 0;
    text-align: center;
    background-image: url(images/BGlogo_55top.png);
    background-repeat: no-repeat;
    background-position: top;
}
.column1 {
    padding-bottom: 50px;
    width: 960px;
    margin: 0 auto;
    position: relative;
}
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50px;           
    text-align: center;
}
/*----------
Other
----------*/
.plainimg {
    border-style: none
}
/*----------
Text styles
----------*/
p {
    font-size: 80%;
    color: #333;
    line-height: 150%;
    text-align: left;
    padding: 1px 15px 1px 15px;
}
h1 {
    font-size: 100%;
    color: #000;
    padding: 0;
}
h2 {
    font-size: 100%;
    font-weight: 500;
    color: #000;
    padding: 0;
    text-align: center;
}
/*----------
Links
----------*/
a.navlink:link, a.navlink:visited {
    text-decoration: none;
    display: inline-block;
    color: #F1F1F1;
    width: 120px;
    text-align: center;
    padding: 0 0 3px 0;
    font-size: 80%;
}
a.navlink:hover, a.navlink:active {
    text-decoration: none;
    display: inline-block;
    color: #FFF;
    background-color: #000;
    width: 120px;
    text-align: centre;
    padding: 0 0 3px 0;
    font-size: 80%;
}
a:link, a:visited {
    text-decoration: none;
    color: #AEAEAE;
}
a:hover, a:active {
    text-decoration: underline;
    color: #999
}

The div arrangement is as follows:

<div id=container>
<div class=header></div>
<div class=column1></div>
<div class=footer></div>
</div>
A: 

Take a look at this: http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page

When it has broken for me in the past I typically have something in the content that is the culprit - padding, invalid markup, etc. If you post a link to your page, you may find a more specific answer.

Jason McCreary
Great stuff.It's at www.gregmusser.com/test
EDIT: Just the Index page and the Garden page are there to test.
Looks like your body tag isn't 100% tall. I added `height: 100%` to the html tag for a quick win. Start there and take a look at the link I originally posted. He has the styles I have used for years. Also, if you don't have it, get Firebug for Firefox. It's great for these types of diagnoses/tweaks.
Jason McCreary
@Jason McCreary: When I inspect the page (now) he *does* have `height: 100%` on the <body>. The footer is still not at the bottom.
Brock Adams
Adding the height to the <html> helps but triggers an unnecessary scrollbar for me. The footer still does not stay fixed.
Brock Adams
@Brock. There are additional styles that remove. Looks like there is some margin/padding styles that I believe trigger the scrollbar. The link and the in my original post has the tried and testing styles. Let's see what the user finds.
Jason McCreary
Hi Jason, funnily enough, that's the guide I used to get a sticky footer! I will try with a 'clear: both' and see if that works. I've updated it now to try your fixes, but it still seems like it's a default padding thing. The site behaves the same in Chrome and Firefox now, and although it's better on the Garden page, the index is still acting up - the footer floats infront of everything.
You need get back to the basics. My guess is that you've added styles and it's kind of a mess. Take 10 minutes and just start over with these elements. As good practice, you should also use a reset stylesheet. I prefer the one by [Eric Meyer](http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/)
Jason McCreary
A: 

As Jason McCreary said, you need to add height to the html CSS.

Use:

html 
{
    height:     100%;
    margin:     0;
    padding:    0;
}

On your pages this triggers an extraneous scrollbar for some reason.

UPDATE:
The scrollbar appears to be triggered by the overflow of the .footer h6.
Adding: bottom: 2.5ex; and line-height: 1; to the footer style appears to clears that.

But a better way is to use a CSS reset.

With no reset, at the minimum, add:

.footer h6 {
    margin: 0;
    padding: 0;
}

.

A CSS reset will also minimize cross-browser variation that busts the layout from platform to platform.

Brock Adams
Hi Brock, I've added the html CSS you supplied, but still unfortunately having problems.It's behaving better in both Firefox and Chrome, and is good on the Garden page, but not on the index.
Hi, @user367232, The page, http://www.gregmusser.com/test/ , doesn't show a CSS reset nor the `bottom: 2.5ex;`. See my updated answer.
Brock Adams
Hi Brock, I've now made the alterations you suggested. Are the h6 changes adequate, or do I need a CSS reset? It makes me nervous, that's all. I will do some more testing with firebug. Let me know if you spot anything!
Hi @user367232, the h6 changes are probably *adequate* for the browser you are using, for the pages as they are. But (1) clients will be using all sorts of different browsers, and each browser has different default settings! (2) What happens when you make future changes? A CSS reset just saves so much grief -- it probably would have helped solving this problem too. So, no, you don't absolutely need one, but I don't know any experienced page-crafter who hasn't learned, the hard way, to use one.
Brock Adams
Thanks Brock, I'll mark this as answered. I've only been producing websites for two years, and still hit a brick wall sometimes! Thanks very much for your tips fella.
You're welcome; glad to help!
Brock Adams
A: 

Here is your problem:

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

Here is the fix:

#container {
min-height:100%;
}

Good stuff:

http://www.w3schools.com/Css/pr_class_position.asp

GaVrA
Hi Gavra, this doesn't seem to affect anything for me.
If we are talking about this site: http://www.gregmusser.com/test/ then you are doing something wrong, because you had position relative on #container, and element with position:absolute will be positioned absolutly from first parent element with position:relative, or if there is none then it will position it self from body.Now i checked again that site, there is no position:relative on #container, and footer is fixed to the bottom...
GaVrA
A: 

Solved. Easy Solution Just put your Footer Division outside of your Container Division.

<div id=container>
    <div class=header></div>
    <div class=column1></div>
</div>
<div class=footer></div>
Starx
Hi Starx, I think having an arrangement like that would mean that it was permanently stuck to the bottom of the browser window, and wouldn't move down if I added a lot of content.
no user367232 the footer is absolutely positioned, so it wont matter if you add or decrease it will remain the same
Starx