Hi all,
I’m using the sticky footer method mentioned here: http://www.cssstickyfooter.com and it all works just fine accept I’m not sure where to place my background so that it tiles all the way up to the footer.
I’ve attached my css file and html file samples. Can anyone help me with this? I’ve looked it over and over and just can’t see it.
If I should just past my code into the thread I can do that too.
Ah ok that simplifies it then if we really don’t need to worry about IE5. Thanks so much for all your explanations.
I’m in the CSS Live class right now also and am learning so much I didn’t know before. I’m really starting to understand CSS more now rather than just trying different things to see if they work or not as I’ve been doing in the past (and then not understanding why it worked or didn’t work).
Yes you could use padding as well and either border or padding would still have the same impact in the broken box model but as we don;t code in quirks mode these days there’s no need to worry about that or a bout ie5 as it is long dead
I prefer border because if you have an absolutely placed child in the (relatively positioned) header then it would takes its co-ordinates from the inner border edge - which is the immediate free space. If you had used padding then you would need to add the padding height to the co-ordinates as the starting position would be the outer padding edge.
Sometimes though you may want something to overlap the header and if you used a border color then it may interfere so in those cases you could use padding.
As usual with css there’s is not really one right answer but an answer that depends on what you are doing at the time
Yes it is a bit confusing and its a shame that we have to resort to these tricks but when you start to think about it you realise why things need to work like this.
To explain simply what’s happening…
we create an element that stretches from the top to the bottom of the viewport exactly (because that’s all we can really do).
We place a footer below this element which means it sits below the viewport and you can’t see it.
Either :
a) drag the footer upwards into view with a negative top margin equal to the height of the footer (which means that content in that div above may be hidden by the footer which is why we then need to add padding bottom to the element above to preserve the space).
Or
b) Drag the outer itself upwards with a negative top margin equal to the height of the footer. The footer now comes into view but the top of the page is above the monitor. That’s why we next add a border-top to the first element inside (usually a header) and again use a border-width equal to the height of the footer. This ensures that content now starts inside the viewport and not above it. everything else is now a normal page.
The three dimensions are always consistent.
footer height
negative margin
soak up height (either padding or border)
The other extra fixes are for various browsers to make them behave and you don’t really need to touch them - just copy and paste and forget about them.
Ok…that does simplify it a lot. In regards to the header you said you can use padding or border. Does it matter which one you use? I guess border is a little bit more cross-browser compliant especially with IE right? Doesn’t IE treat the box model differently in some versions? Would it treat the padding differently in some versions if you used the padding on top of the header instead of the border? Or are both pretty much the same?
Hi Paul,
Thanks so much for fixing my code. I think I’m starting to understand it a little bit more now. I had read your article before this on our sticky footer I just didn’t quite understand it all. But now seeing how you adjusted mine it helps me to understand it a bit better. I think I’m more of a visual learner though, so I think I might try to draw this out somehow so I can understand it better.
Your explanation about the border on top of the header helps a lot also. That makes more sense than always messing with padding at the bottom.
Thanks so much for your help it works just perfectly now.
It doesn’t really matter but it just feels neater to use the top border on the header and then you can forget about it. Either way is good but if you add padding-bottom to the last element you have to remember not to add anything else or change where the padding is. Once it’s applied to the header you can forget about it forever.
It is also more reliable to drag the outer upwards rather than dragging the footer over the outer because Firefox wouldn’t need a soak up (if floats were in the mix) but IE would which meant they behaved differently and stopped at different points when padding was added.
Paul, have you always been using the top for footer room or did you switch? I use bottom-room, prolly cause that’s the first way I saw it and it made sense, but is there maybe an advantage to top-soaking?
Here is your code adjusted to work (see the comments I have added in the css). The css replaces all your css as I removed the broken code and some unnecessary rules (and your conditional comments are no longer needed either).
Posting your code certainly goes faster. You can wait days for approval.
What background image, and on who does it tile??
I don’t use any of the code from that site. Frankly, I expect my users to not be so dumb as to resize a browser and then not hit f5 if it looks goofy (or am I weird for using it all the time to correct Firefox?). And I warn people against setting all padding to zero. That can turn into FAIL if you have forms. It’s not like divs come with padding in any browser anyway (the body does, but most of the time you won’t see it).
*edit what background images, where do you want them??