A CSS Sticky Footer that Works in 2009 (Chrome too)
UPDATE: This sticky footer solution has been updated since the launch of Internet Exploder 8. More recent blog post about it is here. Most the typical problems some people encounter are the same and many have been discussed in the comments below on this post. If you are having problems there is a good chance you’ll find your solution below from someone else who ran into similar issues.
For those that don’t know a sticky footer is a footer that sticks to the bottom of the browser window when the content area is too short to push it down on its own. Having a footer float part way up the page can look like poor design on some sites.
A working solution that actually makes the footer stick to the bottom of the page can be found here.
I’ve played with various methods for creating CSS layouts that use sticky footers but have always found a browser or two that just messes it up. Googling around for sticky footer solutions unfortunately takes you to older pages with outdated techniques. It’s times like that that the age and trust factor of Google’s algorithm fails at delivering true relevance.
Another problem with other solutions I tested was that they broke down when using a floating 2 column layout. The floating content area and sidebar would collapse margins, or something, and the footer would no longer stick. There were also problems with resizing browser windows. As the window was shrunk shorter the footer would break out of its stuck position and sometimes cause footer/content overlap.
One well known solution does work but requires an extra push with an empty div element. Not truly semantic HTML coding, but it works. Though others report that it faces the same problems with floating layouts and resizing browser windows.
I do believe I have a solution that is working now, in 2009, across many browsers. All the big important ones and a whole pile of small ones. Google Chrome in particular was still causing me problems but I fixed that too. It works with floating multi-column layouts and we don’t get re-sized browser window issues. Details on how to use it can be found here.
So as to help others find this new, and working solution sticky footer solution, I created a new website CSS Sticky Footer. The hope is that other will find the solution useful and start linking to it. In time it should rank well in Google and those seeking a footer layout that sticks to the bottom of the page can then find a more updated version than some of those old ones that still rank well.
If you have comments about this sticky footer code you can discuss it here in the comments below.
DoFollow links available for frequent commentors.
340 Comments to “A CSS Sticky Footer that Works in 2009 (Chrome too)”
Leave a Comment
RSS Feed
The Topics
- I’m Such a Nerd - Now a Wine Nerd
- An Ode to a Very Special Little Rescue Dog
- Centering a Div in IE9 Using margin:auto
- Playing with HTML5 for First Time
- My Wife is a Food Blogger
- Designing and Coding a Mobile Version of your Website
- A CSS Sticky Footer that Works in 2009 (Chrome too) (340)
- New iGoogle with Left Nav Bar is the SUCK! (194)
- My Cool Ass CB750 Cafe Racer (104)
- Centering a Div in IE8 Using margin:auto (15)
- The State of Local Search in Canada (14)
Recent Stuff












I don’t even care what it does- the duct tape RULES.
_____ Thank you sooooo much! _______
Finally something that works.
I am recommending it to everyone.
Cheers
Does this sticky footer work if additional content or HTML is injected into the page via innerHTML or DOM? If a DIV is injected into the page and increases the height of the page, will your sticky footer account for that?
@Stephen, I believe that if you inject an other div inside of “main” div it should work. But you may need to watch out for creating spacing using margin top or bottom, instead you may need to rely on using padding instead.
The home page of the site gives the example for when content is short but you want to make the footer stick farther down, but if you check the how to page or the browser list page you’ll see the content is really long there and the footer gets pushed down to bottom of content without sticking to bottom of browser window, before you scroll down to see rest of page. Also on the browser list page I have 2 divs, inside the content div, floating the browser list to one side and the screen shoots to the other. So maybe that covers what you are asking.
As for DOM, or java injected innerHTML I’m not certain as these are not things i’m all that familiar with but if your stylesheet accounts for them properly, inside the framework of the sticky footer code, then it should work, I would think.
i find that this works a treat when my content is short–footer sticks as expected; but when the content is longer, i have an annoying gap at the bottom below the footer in firefox3 and chrome. in ie6, the footer sits on the bottom, but then, it’s ie6.
any thoughts as to what could be causing this gap?
@chris - check to see if some of your divs are using margins for spacing on top or bottom. You might have to switch them to padding instead.
only margin: 0 auto; to center my layout.
i think i’m complicating the situation with 3 columns, set up like this:
with #innerWrap and .sidebar floated left and #content floated right and all the applicable sticky footer particulars.
any thoughts?
oops, code stripped…sorry.
check your email chris
Seems to have worked perfectly, well done, thanks a bunch
For the clear fix, have you thought of using the overflow trick?
http://www.quirksmode.org/css/clearing.html
I have used this for a while and it is great because it’s way less to remember and I have had little to no problems with it.
overflow: auto; or overflow: hidden; cover all of the use cases quite nicely.
Plus it will cut your CSS almost in half.
I’ll have to try the overflow trick and see if it works here too. As far as remembering code snippets, like the clearfix, what’s there to remember? cut and paste does wonders
Steve,
I’m using your sticky footer method, and it’s working well, however in IE6 its making the page super long (even with no text or anything in the main body), and causing a gap between my header and top section of my content. Any ideas why this is happening? I’m not using any margin or anything on any height portions.
@x3ro, I have no idea without seeing your code. Not a problem I’ve come across before or others have mentioned. You have to have something wrong in there messing things up.
[…] come px invece di pt o em. Articolo originariamente pubblicato su http://www.cssstickyfooter.com e http://www.stever.ca, all rights reserved. Tradotto con l’esplicito consenso […]
Cameron Adams came up with this code in 2005.
http://themaninblue.com/writing/perspective/2005/08/29/
I’d like to see you put a zip file with all the needed files online, that we could easily download to play around with.
I had to grab your whole website, which is a lot more than I really needed.
@RB, the man in blue version has some similarities but is not quite the same, and does not add the clearfix hack.
@Fred, a zip file, I might just do that.
Just a note for ASP.net websites: form tag breaks the sticky footer layout - to fix that, add form tag to the height rule:
html, body, form, #wrap {height: 100%;}
and everything will work perfectly
*Note - that’s the form tag that sits outside all the divs on the page. Thanks for posting this one ReTox, I don’t work with ASP.net (Stever)
You guys rock, i have been tweetering about your new code for while and just used it now for one of my projects to force out the old one i was using from someone else and it works perfect, exactly as it says on the tin!
I have recommended your work and very much grateful for the knowledge.
It works only in Firefox…
*Giorgos, I think you’re doing it wrong (stever)
Wow, total disregard to where your ideas came from. This is not a new method as RB pointed out Cameron Adams came up with the code. You might have slightly altered it but the concept came from him. It’s great that you might have improved it but at least give him a shout-out since your method is 90% his.
Could you explain how your code is different? Just adding the clearfix (again, not your code) does not qualify as improving the underlying method. I am interested to hear how your method is better and how exactly you improved it?
@requiredName, if you take a look at the “how too page” you’ll see I gave credit to a 2004 article from A List Apart, Exploring footers. It pre-dates the Man in Blue by 1 year.
Cameron’s HTML code is indeed almost identical, but there are some differences in the CSS.
In the #wrap div, same as #nonFooter in Man in Blue, I don’t have any positioning and I add a height:auto. In the footer I added a clear:both and, yes, I stuck in the old trusty clearfix hack onto the #main div.
Before I came up with this solution I tried a bunch of various ones I could find in Google (ryan faits, man-in-blue, and others I can’t remember) and was always finding situations where it broke in one browser or another, or when using floating two column layouts. So I started over, mixed and matched, cut and pasted, added things, deleted things, hacked and hacked until I found a solution that I could actually make work.
Frankly with all the mixing, matching and hacking I stumbled blindly into a solution that works and it happened to be an improvement on other solutions out there.
So it’s 90% Cameron Adams’s, 90% Ryan Fait’s, 90% Bobby Van Der Sluis’s (the ‘A List Apart’ article), 90% WC3’s, 90% browser developers (though i would like to shoot some of them) and, most of all, 90% of the web designers out there looking for ways to make footers stick to the bottom of a page.
Hey Stever I’m loving this solution!
I’m going for a certain layout with #header 100% wide, #main fixed-width & centered, #footer fixed width & centered, and a background image applied to #wrap.
I have it mostly working, but I can’t seem to make the #main container extend down to the top of the footer. Is this possible to do?
I have a demo set up here: http://dev.oniegirl.com/stick/
I don’t mind if things get more complex, as long as it works! Maybe #header needs to be outside (above) the sticky footer solution, and then I could apply the background directly to the body element and set the fixed width on #wrap?
Another pair of eyes on it would be appreciated.
Thanks
Thanks for this, it’s indeed the most robust solution. If anyone’s having trouble with gaps, it’s most likely due to CSS’s collapsing margins. You mention this but let me allow a quick explanation, since it can be a frustrating factor. Many people are not aware of this but margins collapse between nested elements, too, not only adjacent ones. It’s pretty counter intuitive but important here. Basically, avoid content elements at the very top or bottom “merging” their margins out into the those elements that need to have top/bottom margins of zero (div#wrap, body etc.) Solutions? Read this piece by Eric Meyer:
http://www.complexspiral.com/publications/uncollapsing-margins/
If you keep that in mind, you won’t have trouble and you can work your way around any layout limitation.
Also, make sure to set the body elemt’s margin-top and margin-bottom to zero. Default browser styles give it margins of ca. 8px which will trip your sticky footer up, so don’t forget that.
@Matt, I think i figured it out. Add your background pattern to the body, not #main then set #main background color the white, width to 800px and auto left right margins to center it.
If you still want the header the stretch to full width then create a 2nd wrapper div (give it new name) starting below header and closing just above the first #wrap div. Set this one to 800 px, centered and white instead of the outer one. That should do it.
[…] having something “glued” onto the side of your browser window. Please give credits to Steve Hatcher and Ryan Faits, as they were the ones who discovered these […]
Thanks for explaining the (very minor) differences between your solution and Cameron Adams. I still don’t know why your changes are an improvement. You haven’t explained why your solution is better. (other than.. “was always finding situations where it broke in one browser or another,”) How do I know your solution won’t break in certain situations? What specifically did you do to keep it from breaking in those certain situations. Your basically saying you came up with it by blind luck.
Crediting an article that Cameron based his solution on doesn’t count as giving proper credit. You literally only changed 2 things about his code (with your mix and match hack fest) and forgot where you got the concept. Yeah right.
Now I’m not saying you didn’t come up with an improvement. I have yet to fully test your solution in real world situations. What I am saying is that it is in bad taste to alter someone’s code very slightly and then claim the solution as your own.
Your response just proves my point. You say it is nearly identical and then later say it is 90% this… 90% that… I think you need to freshen up on your math skills. It’s 90% Cameron’s… PERIOD.
http://themaninblue.com/writing/perspective/2005/08/29/
ok, requiredName, if you insist. Sheesh.
And yeah, there was a fair bit of dumb luck involved. I’m not a CSS wizard by any means. Collapsing margins still dumbfound me regularly.
Stever,
I’m replying late, but you can see part of my problem here:
http://www.subthump2.info
In FF and IE7 the page works great. In IE6, the page is stretched way longer than it needs to be.
Any ideas on why IE6 is doing this?
x3ro, kind of hard to tell what might be the problem there with all those tables. I haven’t use a table based layout in years and avoid them like the plague.
Just a guess, I see some of your table cells have heights, they might be causing the same problem as using margins, instead of padding, on elements and making it all push down by the total height of all those cell heights??? Just a wild guess though.
Thanks man!!!! This little thing make a lot of big and good things to web designers and developers!!!
Would this work if you are using the 960 grid system?
@mike, I’ve only just come across the 960 grid system myself, and have not had time to try to use it yet, so I am not sure. In principle there is no reason why it can’t be made to work.
I am new at programming web pages…
I am using VisualStudio 2008 and had to remove the “body >” from the following line:
body > #wrap {height: auto; min-height: 100%;}
It works fine with out the body > part but with body > the footer sticks to the size of the window and disregards the size of the content.
Anyone else run into this?
@Scott, read ReTox’s comment above about .net sites. You may need to add the form tag to the top line like this;
html, body, form, #wrap {height:100%}
[…] footer). So you can check for more information the site http://www.cssstickyfooter.com and the post A CSS Sticky Footer that Works in 2009 (Chrome too) which is with many comments - both by Steve […]
Thanks for this solution.
Having to put the footer outside the wrapper requires an extra little tweak in some situations (centered fixed-width wrapper with all floating divs inside, such that the footer then just needs to be centered, so no biggie), but making it fly in IE is a major selling point.
I personally think there’s a special place in hell for IE (pronounced “aaayyyyeeee!!), seeing as how we all spend untold extra hours making it not break our CSS layouts. But in this life, we are suffering to build character, right?
Howdy Steve,
I created a completely stripped down page, with no additional css to try out your solution. I was getting vertical scroll bars (in both firefox and safari). Firebug showed the only margin being set was the margin-bottom to match the footer. Then it dawned on me that it might be the default margin causing the problem. I explicitly added margin: 0px after you set the height to 100% and it took care of the problem.
Hi, thanks for this sweet solution
”
Stephen on January 22nd, 2009 wrote:
Does this sticky footer work if additional content or HTML is injected into the page via innerHTML or DOM? …
”
Yeah I have tested it, Im using ajax to load some content, getting xml as response and then inserting the node tree into a div trough DOM that’s inside of , and it just work as spected. Be carefull with your css, as initially it seemed not to work for me because some other declarations
[…] sehr an Cameron Adams’ “footerStick Alt” erinnert. Sie ist aber, wie der Autor in einem Kommentar beteuert, an wenigen Stellen verändert/modernisiert. Schön einfach und cross-browser […]
I was having a problem with gaps at the bottom under the footer, like others here have mentioned. I found that in my case it was due to some javascript I needed to load at the end of the page. I fiddled with it for days but I could not get rid of that gap without removing the javascript . . . until I finally got lucky and stumbled on a solution!
All I needed to do was add a negative margin to the footer: ‘margin-bottom: -1px’
Hope this trick helps others as I know how frustrating these css issues can be.
oh no! - just checked today and this is a bit broken in IE8.
If you refresh the page, then expand the browsers height, the footer stays at the point it was refreshed at. On other browsers it expands with the browser’s height.
Its almost as though the min-height 100% is being ignored. I’ve noticed the same thing on Opera on the PC.
So close, but then they bring another frickin browser out.
will post back if I solve it but no luck yet….
@mattyk OH NO! Is right. I so hate Microsoft and their browsers. I won’t get to test things out in IE8 for a while, just too busy.
But another browser with new quirks. Bastards!
I do not know what is going on with my computer but none of the sticky css bottom bars are working in firefox, chrome, or IE. Any ideas what is wrong here?
I didn’t have time to test it out properly but “display:table” might rescue this.
If this works in all “modern browsers” we might be able to do something with the 100% height that way. We could then use this technique in an IE6 only style sheet. will have to try this when I get time.
make that an IE7 and IE6 style sheet. doh!
I tried to read all comments and it might have been covered but why is there clear:both for div#main in finerstyle.css if main div has class=”clearfix” in html?
Stever says : Maybe I just screwed up and it does not need to be there.
@seth, without more detail I don’t know what the problem might be.
Don’t worry about looking at my problem as I have fixed it.
The main requirement was to manually clear all the browser defaults in the CSS file.
One this was done most of my issues went away.
The other thing I found is that there seems to be a minimum footer size requirement for this to work. I currently have the footer set to 18px and it works fine but if I set it to 16px I get a small gap under the footer which is not a problem with IE but is slightly with Firefox.
As the difference between 18 and 16 pixels is the same as a fly’s todger I am going to leave it as it is.
Thanks for the code… we all owe you a virtual beer!
First off thanks so much for this solution!
I’ve found a problem though:
Like some others, I made a completely stripped down page and used the CSS provided and saw vertical scroll bars on chrome and firefox.
Adding
* {margin:0;padding:0;}
solves the problem.
The reason scrollbars don’t show up on cssstickyfooter.com is because this extra line of CSS is included at the top of the stylesheet at http://www.cssstickyfooter.com/finerstyle.css
I updated the CSS file to include the margin:0 declaration on everything. Just so it’s clearer for those finding the solution for the first time.
Great idea - although I am having a slight problem with it. The footer is sticking as it should but it is below the page. So if I am on a page with little content I have to scroll to see the footer. I am using a two column floated layout (left col float left and right col float right) but even when I remove these I still have the same problem so I don’t think this is causing it?
So I started again with a completely stripped down version and I am still getting the same problem with the actual code used?
Any ideas? The site I am working on is not online but I can email you the code if you would be so kind as to help me out?
Thanks
Please ignore the above - after six hours of looking at the code I just realised I had the padding on the wrong div!!!
Thanks and great trick I will be using again!
Steve
Using the css sticky footer but for some reason I have to scroll to get to the footer, even though the page content fits snugly on the page. It seems the 100% height wrap div is pushing it too far down so I need to scroll to see it. Any ideas?
First off: agreed that this seems like a great, simple solution. Thanks.
I am actually having the exact same problem that Steve described on April 4th of the footer sticking alright, but on pages with not enough content to fill the page the footer is going below the window height and adding a vertical scrollbar. I too have troubleshooted, checked margins, etc. and I’m still having the problem (I haven’t been as lucky as Steve in finding a simple padding mistake… though I’m sure that’s all it is…)
Please offer any advice you’ve got if you have the time. Thanks.
Without sounding pompous (and I don’t usually butt-in like this) but sorry to say that I actually came up with the original idea way back in 2003 and all others have been copies of my technique since.:) (either intentionally or unintentionally).
I don’t mind my ideas being copied/used anyway and the proof can be seen in this thread dated December 2003 (and mentioned on Position Is Everything around the same time).
http://www.sitepoint.com/forums/showthread.php?t=143801
This pre-dates all other versions that I know of.
A new improved sticky footer can be found here.
http://www.pmob.co.uk/temp/sticky-footer.htm
The website displays correctly in all browsers I’ve tried but in IE8 it only resizes correctly when in compatibility mode. Can someone else verify, maybe they made a tweak when they brought it out of beta.
Thanks
@Paul O’Brien, well then we all owe you a little gratitude it seems!
@Ian, yes someone else pointed out that IE8 is now causing problems. I’ve yet to test it myself.
Sorry if my last post sounded like a side-swipe but it wasn’t meant to be.
Regarding IE8 then yes it’s behaving almost exactly as Opera behaves and the footer doesn’t resize unless you refresh (or drag the browser from the side). The same fix will work that I originally used for Opera and old safari versions but is rather inelegant.
It’s a simple 1px high 100% float as seen here.
http://www.pmob.co.uk/temp/sticky-footer2.htm
However, It’s not a solution I like.
Thanks Paul O’brien for that solution, I’ll check ot out when I get time - IE8 definitely behaves like Opera unless its in compatability mode. Seems a shame to use this mode just to get one part of the layout working so could be an alternative.
I’m wondering if there is a way to use CSS Tables for this. If there is maybe that’s the way to go and then we use some kind of hack for ie 6 and 7…
Hi Mattyk, As you suggested IE8 can be brought into line with a simple display:table and height declaration.
#outer{
display:table;
height:100%;
}
It’s best to hide the display:table from gecko otherwise you’d need to insert a display:table-row element because gecko can’t handle display:table on its own and misplaces content on first page load (especially noticable when viewing online).
Opera is still broken even with display:table and the full table display structure.
I forgot to mention the above code should only be given to IE8 via conditional comments
Hi there, i have tried this and had so many problems with it - I know the code must work, but i can’t seem to get it right as it screws my whole page up.
If anybody could help me, i’d be very thankful.
My email address is lukegw@hotmail.com (hope im not breaking any rules)
If you email me, ill email you my html and css code.
Thanks in advance everyone!!!!!!!
Lukegw
I can’t get this solution to work on my site. The site is made with Drupal’s CMS and it’s called http://www.brainplay.ie
I’ve tried to tweak it in many different ways of doing it but I’m not a programmer so the answer could be starring me in the face.
The relevant CSS is found at the bottom of http://brainplay.ie/themes/lightfantastic/style.css
I would appreciate any advice? Thanks
You are applying the 100% to the wrong element Ciaran. It must be applied to the first element on the page which is #container in your layout.
You “cannot” pass on the 100% height into any other nested elements because the height will collapse to auto in all browsers except ie6.
You cannot base an elements height on a min-height element. If you actually gave the parent a fixed height then it wouldn’t be able to grow anyway. This is the paradox and therefore you can only use the first container on the page because it bases its height on the body 100% height.
Don’t use the height:auto over-ride method as ie7 has a bug with that.Just give ie6 the height:100% using the star selector hack.
You need to use something like this:
div#container{
min-height:100%;
background:#fff;
}
* html #container{height:100%}
#main {padding-bottom: 158px;} /* must be same height as the footer */
#footer {position: relative;
width:960px;
margin:-158px auto 0;/* negative value of footer height */
height: 158px;
clear:both;
background: #FFFFFF url(./assets/images/bottom-colours.jpg) no-repeat;
}
Of course FF3 doesn’t need the padding-bottom on#main but IE does.
If you want a method that works everywhere (including ie8 and opera)then there is an example here but is a little more involved:
http://www.pmob.co.uk/temp/sticky-footer-ie8new.htm
(Please remove if linking isn’t allowed).
I also forgot to mention that the footer now needs to be outside of the container and needs to be moved down.
I was having a heck of a time getting this working (#content column wasn’t being cleared yet #side was). Spent ages staring blankly at the code, moving things around, trying to work it out. Even tried redoing the page using Paul’s method (no luck). Then a mate took a look at it and spotted it pretty quickly.
Culprit turned out to be declaring a height on #content. Min-height is ok but height breaks the layout. Weird. Hope that helps someone!
@Grant, yes any of the main elements of the sticky layout must not have set heights, except the footer, or use vertical margins, else it breaks the 100% and auto heights.
Instead use separate divs for boxes inside, those can have set heights if you needed to use them. I believe you can even use vertical margins on other divs that sit inside the content div.
Paul O’Brien - just a quick thanks for putting that demo up. I’ve checked it on Chrome 1.01 and can confirm it works there too.
I noticed that IE8 is out as an “important update” now so I’m guessing it won’t be long before it overtakes IE7.
Hello All,
I was led to this solution through the CSS Creator forums. I tried it and I have a huge gapping margin that appears in most browsers between my footer and content. I think I have one or two “height”s in all of my CSS (not on the major divs) and I have tried replacing all (but one) of my vertical margins with padding. I am lost : is my JavaScript a problem? Are my floats a problem? I mentioned this problem in the forum and no one has replied. Any help would be appreciated. (http://www.fussandfeathers.com/about-sarahwrose.html).
Hi Stever,
In the first few comments you replied to Chris via e-mail. I’m having the same problem and the code he pasted looked very similar to what I’m using. Could you post the solution you sent him or e-mail it to me?
Thanks!
Hello. I’m having a lot of problems with this and I cannot seem to find a solution. I am wondering if my javascript is interfering. I am getting a huge gap in between my footer and my content. I have looked at all the margins / heights in the content and I cannot seem to figure out what is causing the gap. I am not looking for someone to solve my problem, I just need someone to point out what is wrong…
Any help will be credited on my blog!
Does anyone have an example of CSS sticky footer working with Blueprint? Just can’t get them to play nice
Cancel that, I think I’ve got this working. I needed to enclose my Blueprint div’s within your wrap div.
Sorry, new to all this
I seem to have a problem when I use this method on a page with short content (in IE7 and FF - IE6 seems to work!). I’m trying to produce a centered two colulm website with a footer whose background colour is the
I’ll finsish typing before submitting this time:
I seem to have a problem when I use this method on a page with short content (in IE7 and FF - IE6 seems to work!). I’m trying to produce a centered two column website with a footer whose background colour is the same as the edges (ie. area around the centered two columns). When the content is short, the ‘main’ container doesn’t reach the footer (ie. there is a gap between the content and footer). I’m pretty sure this isn’t to do with my code, because if you change the background colour of Stever’s example code and strip out most of the content, you can see the effect.
I’ve been trying to produce this simple website using CSS for ages now - I’m hoping that this will be the answer I’ve been looking for… Any ideas much appreciated.
HI Sarah,
The problem is that you are applying the 100% height routine to an inner element and 100% height doesn’t work like that because the height collapses to auto.
You need to use the first element on the page to carry the height like so:
html,body{
font-size: 100%;
height: 100%;
margin: 0;
padding:0;
}
body{
background:url(http://www.fussandfeathers.com/images/background.png) repeat;
}
/*Container NOT including Footer*/
#wrapper{
background: white;
width: 1035px;
margin: 0 auto;
min-height:100%;
}
* html #wrapper{height:100%}
#container {
width: 1035px;
margin: 0 auto;
padding-bottom: 6.5em;
font-family: century gothic, avant garde, arial, sans-serif;
}
hi there - i’m having a slight prob with the stickyfooter: if there is enough content on the page, it works fine in IE FF & Safari. but if there is minimal content, it only stays on the bottom in IE. i’ve deduced that the problem is that i have my body set to display:table. however this was the only way i found to keep my background image in position (otherwise it would move to the left and out of the window as i shrunk my browser window, while all my other content stayed put & scroll bars appear, etc.)
does this problem ring a bell to anyone?
Hi Nicky, if its a background image on the body then remove the display:table and just set a min-width on the html element equal to the smallest that you want the page to be to fit your background image.
e.g.
html{min-width:760px}
If you use display table on the body then you would have needed to make the outer wrapper display:table-cell but older gecko doesn’t like to jump straight onto table-cell without an intermediate element set to display:table-row so is best avoided for the 100% height routines where gecko is concerned.
that did it! thanks!!
Hi there. I am trying to nest a 100% high innerwrapper within the 100% high outerwrapper so that I can add a background tile to the body (diagonal lines), a background to the outerwrapper (drop shadow), and a background to the innerwrapper (a vertical gradient). The body and outerwrapper are working fine, but the innerwrapper is collapsing to nothing as I can’t figure out how to pass the 100% to it properly.
Any suggestions would be greatly appreciated.
I noticed someone mentioned it earlier, but if you simply put an overflow: auto; on your wrapper you should be able to do away with the whole clearfix hack.
Just wanted to say thanks for a nice clean, compliant peice of work
@Brad - The simple answer is you cannot have more than one 100% high element. Any further nestings collapse to height:auto because you cannot base height on a parent that has min-height set.
If you give the elements an actual 100% height then none of them can ever grow and will fail also.
100% height is mis-understood by nearly everyone and when you base an element on 100% of its parent’s height then that parent must have a height defined also. If that is the case then the elements are all fixed in height and can never grow. If that is not the case the heights simply collapse to auto.
You can use display:table on the elements for ie8 and other browsers as that would allow height:100% to be treated as a minimum but ie7 and under do not understand it.
Your only realistic option is to try and apply the shadow and the vertical gradient in one image on the main outer.
There is also a method of using absolute overlays devised by me but is a little complicated to implement. You can find it here:
http://www.search-this.com/2008/06/04/css-bordering-on-the-ridiculous/
(Admin:Please remove link if not allowed)
After much gnashing of teeth and pulling of what little hair I finally got it to work using the even column technique out of the Tripoli framework. I basically made the innerwrapper another even column, which in theory you could do all day long with as many wrappers as you would like, each one 100% of the last. I have to do a bit more testing but so far it seems to work with long content and short without any problems back to IE6.
Hi Brad, Are you sure that’s working? If you nest elements of 100% height then the elements can never grow pass the bottom of the viewport because that is the initial 100% and the background will be cut off below the fold.
Unless you are using display:table or using an overflowing technique where the inner element also has the same background defined and then takes over as it bursts out of the parent. IE7 used to have problems with this in some cases though.
Yes mate, so far it seems to be working both with long and short content. You’ll have to look at the Tripoli framework to see how he does his equal columns to better understand but it does work and if my theory holds true you could have an infinite number of wrappers all 100% long.
I’ve sent you an email btw.
Hi Brad,
I had a look at the layout and you completely misunderstand how it works. There are no nested 100% high wrappers at all because as I mentioned earlier that will not work.
The method used in that layout is the one devised by Alex Robinson and featured on PIE called in search of “The One True Layuout”.
It uses massive negative margins and bottom padding combined with overflow:hidden to allow the columns to equalise.
padding-top: 32767px!important;
margin-bottom: -32767px!important;
It is a clever technique but unfortunately is very buggy.
The worst bug is that in-page links (fragment identifiers) cause the page to be unusable.
If you link to any “in-page” content (e.g. href=”#test”) say half way down the page then the page scrolls to the element concerned but then cuts off any content above. This is eveident in your layout if you just add an in page link to test.
This problem is a showstopper for most sites as it means you cannot have any in page links in your whole site. If that doesn’t worry you then you should be ok but there are other bugs and you should read the caveat on the original site here to make sure it is suitable for you.
http://www.positioniseverything.net/articles/onetruelayout/appendix/equalheightproblems
The absolute overlay method of mine that I referred to a few posts ago does not suffer from any of these bugs and allows for equal columns as you like (within reason).
Hope that explains it
Been looking for something like this awhile. Thanks for the fix!
Hi Stever.
I know this must work (the demos are working fine in all my browsers), but I cannot seem to get the footers in the development page for my site working in any browser.
The main page in my link is not yet using the technique, but all others pages except “home” from the navigation run via an engine which has the method included. Can anyone see where I might be going wrong?
I’ve checked the various height and margin settings, renamed the divs (except footer, kept it at #wrapper-footer and adjusted the css in the ‘default.css’ file) to just #wrap and #main with the clearfix class added to the main, but the footers are still just hanging onto the bottom of any page with any content. Also - in IE I get a really long length of scroll space under the footer if the page content is extensive.
I have a base css reset file that is before the default.css is called. Could the problem be there?
Also - please excuse no crediting in the site as yet, but I will be including credits on any fixes/hacks or 3rd party code…just trying to get the sucker right first.
Hi Brendon,
You have some errors in your html and css logic.
First of all you have wrapped the deprecated center tag around the whole page and this will kill the 100% height in one fell swoop because it carries no height that #wrap can use and therefore all heights collapse to auto.
Remove the center tag and just use auto side margins on #wrap to center the page.
At the bottom of the html you have an opening div above the footer when it should be a closing div.
Remember that #wrap must close before the footer starts and then the footer can also be centred with auto margins.
Then adjust the css as follows.
#wrap{margin:auto}
#wrapper-footer {
margin:-83px auto 0; /* negative value of footer height */
}
If you make those corrections the page will work as I have tested it locally on your code.
Thanks Paul. Appreciate your efforts! Kicking myself for missing that closing div tag…makes perfect sense. Thanks again for your help on this.
THANKS! This is the 20th solution I checked and THE FIRST that worked! I LOVE YOU ;D
I’m having a slight problem with the footer sitting a few pixels from the bottom of the browser edge.
Right now all seems well in Internet Explorer, but on pages with a scroll bar in Firefox, there is about a 4 pixel gap. Pages without a scroll bar (vertical scroll bar by the way) in Firefox work fine as well.
Not sure where things went awry.
I’m having trouble with the sticky footer in Explorer 5.5. I’ve checked your page at http://www.cssstickyfooter.com/ in net renderer http://ipinfo.info/netrenderer/ and like my page at http://www.maisiefantaisie.co.uk/test/index.html it doesn’t center. I’ve heard that normally to center a layout in IE5.5 you would style the body tag with text-align:center;
then the #wrap with text-align:left;
But with your sticky footer it looks like this doesn’t work. Basically I think explorer 5.5 doesn’t like the auto margins. I’m an amateur and would really appreciate it if you could make it work in explorer 5.5. I can’t use the footer otherwise and I really like it!
Daron this has nothing to do with the footer technique and is simply the fact that Ie5.x doesn’t understand that auto margins are supposed to center the element.
For ie5.x you need to add text-align:center on the parent of the element you want centred. You have to do this for every element that needs to be centred in ie5.x.
That could be the body element for a centred page but that won’t cater for all inner elements where text is aligned left.
In your page you would need this.
body{text-align:center}
#wrap{text-align:center}
#logo{text-align:left}
#main{text-align:left}
This post is just great, it’s the best I’ve found, thank you very much for sharing it!
However I encounter an issue, maybe you will be able to explain it. At some point the footer was stuck to the bottom of the page and moved according to the browser size (very good), but when I reached the limit of the content, it disappeared suddenly instead of disappearing gradually. After some researches, I found that my content had the “float: left;” property, and that is what caused the problem. Do you have any idea why?
Did you clear the floats?
It seems to be the solution! thank you very much!
Hi, anybody know a way to make that the #wrap appear over the footer if the size of the screen are small ?
Thnxs
I’m wondering…
Does it work on Camino 1.6.7 and Firefox 3.0.5?
I seem to have some troubles in these browsers..
Anyway, thank you for this!
Rather strange problem I’m dealing with!
I had problems with a little extra space (1px) below my footer when the page is long. Works just fine for short pages. So, I swapped my margins over for padding, but still, no dice.
Turns out, it might be choice of font-family and font-size that is the culprit! Monospaced (e.g. Courier) works at 11px works, others don’t. Any ideas?
@ Tom: IE (and some other browsers at times) has a rounding bug and if the viewport is an odd number of pixels high it rounds the measurement up or down and makes the whole thing 1px out.
There isn’t much you can do about it except to leave the footer overhanging the bottom at by 1px to cover the gap. Of course this means the vertical scrollbar gets triggered because the page is 1px higher than the viewport.
This isn’t anything to do with the footer method but just that it exposes the browsers inadequacies. IE (ie6 mainly)will also round absolute measurements of “bottom” and “right” by 1px and will always be 1px out on odd pixel measurements in a fluid container.
Ok, it works very well, I had made a mistake in my code!
Thanks Paul, much appreciated.
Hi I thanks for creating this site its helped me no end BUT i do have a problem. I have been trying to do the same as Matt whom posted on the 6th Feb this year. I have tried changing the code as per instructions using only colors but for some reason I cannot get it to work! Can someone please help me? I cant get the div #main to be forced to the top of the footer.
OR if matt is still watching this did you fix your problem? If so can you give a gentle nudge as to where you have used it?
TIA
Tuppers
This may be a dumb question but I’ll ask anyways. If one of my pages does not contain enough content to fill the browser window, shouldn’t the footer still stick to the bottom? It’s not doing that for me, any advice?
I am building a site in Dreamweaver CS3, I figured I’d get the sticky footer issue resolved first before I start anything else.
I am a relative newbie, especially with coding. I think I’ve done what was described on http://www.cssstickyfooter.com/ and although the footer is at the bottom of the browser there also seems to be empty space (looks like space equal to the footer height) below it. Not sure what I’ve done wrong.
Hi there,
I’m trying to use the CSS sticky footer together with the 960 grid system, but I just can’t seem to get it to work. I’m trying to implement it at this site – hopefully some of you will be able to help me.
http://larsvmusic.dk/site/musik/
Regarding my last post - as you can see now, the footer isn’t even showing…
Thanks for the IE8 fix Paul O’Brien “Display:table and height declaration.”
#outer{
display:table;
height:100%;
}
Worked great!
Does anyone know how to make it work in Wordpress?
HELP Please! I’ve got the sticky footer working great. It’s works like a dream…thanks.
I have a client using Adobe Contribute to edit their content. When they edit a page (wysiwyg mode) the footer appears half the way up the screen and hides content. When they are typing content above the footer, it doesn’t push down and the content goes underneath the footer.
Works great in Browsers, but a huge problem if clients want to update content.
Does anybody know of any solutions that may help? Do i need to change the Z Index or can i hide it when not viewed in a browser?
Thanks in Advance.
Great Great. Thanks so much.
@ Johnweb I just finish a wordpress version with the stickyfooter and it works.
http://www.treow.net/_treow02/pied-de-page
It depend of your theme. You can use WP Framework to build one :
http://wpframework.com/
My sticky footer won’t stay put in IE5. I thought it was just mine so I checked your website and same problem. Though this one http://ryanfait.com/sticky-footer/ does stay at the bottom of the page. Using windows XP IE5 (vers 7.0.5730). Any soulutions?
@daron
Do you know if there is a big enough percentage of IE 5 users for your project? If the percentage is low enough I would consider dropping all CSS support for IE5. Or you could serve them a really simple style sheet.
From experience I’d say that trying anything too complicated with IE5 will cost you too much time. If your client insists on IE5 then consider charging for extra development time. This browser was realeased in 1999!
Hope that helps!
M
@daron, the numbers of users still on IE5 is so low you should just ignore them, seriously. Here at the w3schools website they show global browser stats. They stopped reporting IE5 last year when it was only 0.5%, and still declining. Project that rate of decline forward to today and it might be around 0.1%, or less. That’s 1 visitor for every 1000, or just about nobody.
I am having a hard time getting this footer to stick. I have checked and double checked my code. I am (*almost) certain I have it correct. I have got it to work in plenty of other sites before. How come it doesn’t work here: http://sfbc.vintom.com
I am trying to get the sticky footer working on this project: http://sfbc.vintom.com
I have had working a million times on other projects, and I have no idea why it isn’t working for me here.
Any thoughts?
Just to note that I to make it work with my design, which has a 10px white padding inside the wrapper, I made the footer height 50px with negative margin-top of -60px, added to the footer a
bottom-margin:10px;
and in stylesheet for the main container set padding-bottom:60px;
Thanks for this. It’s the first one that I’ve been able to get to work in my wordpress custom theme… still in development so no link to it in action.
Im not sure what is going on with this , but I cant seem to get it to work on FF Safari.
I have attempted many variations, and eventually copied and pasted the two examples and still no-go. It just sticks the footer at the bottom of the page:
Am I missing something, or have I not had enough caffeine?
html, body, #wrap {height: 100%;}
body > #wrap {height: auto; min-height: 100%;}
#main {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;}
A note for ASP.NET developers:
If your div#wrap resides inside of form tag, make sure to change CSS from:
“body > #wrap {…}” to
“form > #wrap {…}”
Hi
i rewriting the code for my new website because safari, chrome and opera dont accept the background position on the bottom and i found your trick, its almost work fine, less the footer.
id add some more pixels to the bottom. does anyone had this problem?
regards
I have the exact same problem as Matt and Tuppers:
http://www.sachagreif.com/stuff/stickyfooter/footer-test1.html
I tried following your instructions, but didn’t understand the part about a double wrap div, so here is the best I came up with:
http://www.sachagreif.com/stuff/stickyfooter/footer-test2.html
This has only been tested in firefox 3.5 by the way. In my particular project, the header and the footer happen to be the same width as the main content, but in my example I made them full width because it’s more common for web layouts.
This is a great use of CSS. We used this for our site, and got it working under a canned program for our CRM in IE 6,7,8 and FF. Unfortunately, when we tried to apply it to a Joomla Template, we are running into some problems in IE6 (I know, I know).
We’ve tried hacking the site and CSS to only mess with IE6 to try and make it work.
What happens is, we get the footer bar pasted right in the middle of the page.
(http://www.strudellstudios.com/ingredients-services/web-development)
Any thoughts on what we could be doing wrong?
@Vin Thomas - You have invalid styles before the body rules which is corrupting the 100% height rules.
This is not valid:
/* Colors */
darkest brown: 1d1312
dark brown: 3f3a38
blue: a6c4d3
light purple: CB99BB
purple: 844370
light grey: EDECEC
/* End Colors */
The text must be inside the comments not outside them.
You are the man! Thank you! Stupid mistake…
@ Sacha - You have a scrollbar because your wrap is 100% high and it starts after the header. Therefore it will be 100% high + the height of the header which will push the footer below the fold.
If the header is a fixed height then you can add the footer height and the header height into one larger negative margin and and apply it to the wrap to bring the footer into view.
Here is an example.
http://www.pmob.co.uk/temp/sticky-f.htm
Thanks a lot of the quick reply and example. But I don’t think I can use a border because I use transparent png’s for shadows and the border would show through.
Also, I’m applying a background on wrap so I need the wrap div to start below the header and not be overlayed on top…
Maybe it’s best if I wait until the real site is online to show you. Also, I understand if you don’t have time to deal with this. If it doesn’t work I can just make sure all pages have enough content to push the footer all the way down.
@Sacha - You can use padding instead of the border I used. I use a border because then absolute elements would start at the right place (if any were being used inside the header).
You still apply your background to #wrap - I don’t see a problem there.
The rules are simple:
You have one (and there can only be one) 100% height element to work with and you must do everything inside that element or make adjustments with negative margins for fixed height elements that lie outside (such as the sticky footer or a full width header).
You can’t start a 100% high element some way down the page and expect it just to go to the bottom. It will go 100% from where it starts.
There is no problem when the header is inside the main wrap but once you move it outside you cause big problems
I found a secondary problem on my site. It turns out I had a two column div inside my wrapper class. That is all fine and good, except that in IE6, the footer floats up to the bottom of the shorter div. I wrote some javascript to make the two columns the same. This ended up pushing the footer to the correct spot (at the bottom.
@Robert - There should be no need for javascript if it is working in other browsers then it will work in IE6 also. You probably didn’t clear your floats or something simple like that.
Note that this code doesn’t work in IE7
min-height: 100%;
height: auto !important;
height: 100%;
See my code in the link I posted for Sacha above for the correct version.
I have very little CSS experience, but thanks to comments on this site and elsewhere I’ve been able to progress from footer in the middle of the page, to a sticky footer with a scroll bar, to almost perfect. While the footer is now sticky and the page looks fine, there is still something pushing it down a bit so that a scroll bar appears. I’ve tried to find where there might be a height or padding issue, but this is where I’ve gotten stuck. If anyone could lend and a hand and point out my error(s) I would be grateful. Btw, I’m using the Copyblogger theme for Wordpress and have been editing the .css and .php pages that came with the theme. Here’s my site: http://jamesgibbon.org
Thanks!
Hi Jim,
You haven’t taken into account the padding you added to the footer as it will increase the height.
You need to do something like this:
#main {
padding-bottom: 65px;
} /* must be same height as the footer */
#footer {
position: relative;
margin-top: -65px; /* negative value of footer height */
height: 30px;
clear:both;
}
#footer {
padding: 15px 0;
background: #000;
border-top: 5px solid #a90000;
color: #fff;
}
I have posted about this before, but I didn’t get much response.
Does anybody know why the ‘Footer’ appears above content in WYSIWYG mode or in editing software.
It is hiding my content and my customers are complaining they can’t see or change the text in edit mode because the footer is hiding content.
Does anybody know how i can ressolve this please? Any help would be gratefully received.
Thanks in advance.
Thanks a lot, Paul! I got it to work using this:
#main {padding-bottom: 50px;} /* must be same height as the footer */
#footer {position: relative;
margin-top: -50px; /* negative value of footer height */
height: 15px;
clear:both;}
#footer { padding: 15px 0; background: #000; border-top: 5px solid #a90000; color: #fff; }
I’m still confused why a footer height of 15px, plus footer padding of 15px and a border of 5px - a total of 35 - is being placed properly by a -50px margin. But maybe there is another 15px of padding somewhere in the code that I needed to account for.
Anyway, thanks a lot for sorting me out!
Hi Dave, The fact is that no wysiwyg can handle CSS properly (none that i’ve seen anyway).
For instance DWCS3 can only handle the very simplest of css in design view. Anything more than the basics and it is useless. If something as expensive as DWcs3 can’t handle it then it’s likely that most other editors will fail also at some stage.
Don’t you have the ability to turn off styles while editing or some similar feature?
@Dave, like Paul said, most editors don’t render proper CSS like a browser should. Upload your files to a web server and let your client view them from a proper web browser.
Guys,
Thanks for your replies. Appreciated.
The thing is, i can work around it as i mainly work through the code. However, my client is using Adobe Contribute to edit their pages. As soon as they choose to edit a page, it goes into WYSIWIG mode and the footer appears above all of the text.
It’s proving to be an issue. I would love to be able to turn this off whilst in edit mode, but unsure if this can be done.
Thanks again,
Dave
I love this sticky footer.
One problem though, on my site (
http://www.kylewebdesigner.com) no matter what I do i always have scrolling, I tried to remove it, but i can’t seem to find the problem.
Any ideas?
I’ve hacked something using overflow:hidden on the body, which obviously is not suitable for pages where the content goes further down the page… but at least it will show you what I’m trying to accomplish:
http://www.sachagreif.com/clients/tfc/forgot-thankyou.php
Note that I’ve only tested this in firefox, don’t know if it works in other browsers.
And here’s an additional explanation of what I need to do:
http://www.sachagreif.com/clients/tfc/stickyfooter.jpg
Nicely done, and thanks for making it public. One quick question, and I’m probably missing something obvious… When trying to stuff everything inside a container div, it breaks… I did change the child selector (”>”), but got no love…
@kyle: You only have scrolling because your content is higher than the viewport. That’s how the sticky footer is supposed to work. It only sits on the bottom of the window if there is little content.
If the content is greater than the viewport height then the footer sits at the end of the document which means you will need to scroll to see it.
A footer that sits at the bottom of the viewport at all times is a fixed positioned footer and is a different technique completely.
If you test your page with little content then you will see that the footer sits at the bottom of the window without a scrollbar (in Firefox anyway as I didn’t test others).
@Sacha: If yu are the same sacha that posted above then I have already explained how to do this and aleady given you an example
Here is the example updated using your images.
http://www.pmob.co.uk/temp/sacha-footer.htm
I don’t know why, but I just couldn’t get it to work. I’ll take one more look at your updated example, but I think I need to read up on CSS a little more so that I can understand the underlying principles better and not just copy/paste your code.
hi… just a small one.
if you resize the window (make it smaller) and a scrollbar appears for left-right scrolling, the footer gets cut off.
you can avoid this by adding the min-width tag.
might not work in all browsers though^^
.footer{min-width:1024px;}
I have some little minor improvement for your article … in “How to Use the Sticky Footer” there is a line missing which sets both margin and padding to zero for all elements … took me long to find out, although it’s so mundane (shame on me)
But thank you a lot, that script works and will really help me!
Thanks so much for the great fix! It worked like a champ in Firefox with the exception of the scroll bar on pages with little content. I followed the instructions in the “How to” section and removed all top margins but I was still having the scrolling problem. I know this may not be the best solution but I adjusted the html, body, #wrap height to 95% in the IE specific style sheet and 99% in the normal stylesheet. That seemed to do the trick. Thank you again for the clear and concise code.
I’ve used this footer before and never had problems. He always worked verry good and I still love website’s with a sticky footer.
But now in my new design i just can’t get it right.In IE6 it looks good but not in IE7, FF3, SAFARI, OPERA. They all have the same problem:
A gap between the footer and the content if the content isn’t long enough. I looked at the code for houres now and just can’t find it.
You can find the website here:
http://www.restaurant-cms.be/restaurant4/index.php
The homepage is made extra long to see if that works, if you click on ‘Historiek’ in the menu at the right you find an extra short page (here you can find the problem).
Would love to have a cool Sticky Footer duct tape icon to use for linking back to cssstickyfooter.com
This works fine for my site. However as soon as I start using padding-top, I get a vertical scroll bar and I need to scroll down to see the footer.
I am not using any margin top or bottom settings.
I have my sticky footer working just fine on a site I’m building, but there’s one thing that I’m having trouble fixing. If you use the Zoom tool in IE7 and Zoom Out to 75% or less, my footer floats up right over my content. I’m sure it’s nothing to do with your code, but I’m just hoping for a suggestion, I can’t seem to figure it out.
http://keystone.thenetforward.com/
I figured out the cause of my issue, it has to do with my overall #wrap having ‘position:relative’ as a style. I recreated the csssticky samplepage, added longer text and assigned ‘position:relative’ to the #wrap, and was able to recreate the problem. If you’re using IE 7, and zoom the page under 100% (try 75%) the footer will ‘float’ up the page.
You can see my test page here:
http://thenetforward.com/projects/test.htm
Not sure what to do about it, if anything, but that’s my issue right now.
@Stever Thanks for making this available to us!
@Ray Man, thank you so very much for the collapsing margins “feature.” I thought when I placed elements in “main” and applied a margin-top to it - which pushed down “main” - it was a problem of setting a positioning context.
@Paul O’Brien Thanks to you as well! Admire your willingness to help!
Anybody else using the 1px padding fix to combat collapsing margins that occurs in elements placed within “wrap” and “main”? Any other solution?
Hi Stever
Please add ikarlik comment on July 9th to the http://www.cssstickyfooter.com/using-sticky-footer-code.html .net area if possible and that is:
A note for ASP.NET developers:
If your div#wrap resides inside of form tag, make sure to change CSS from:
“body > #wrap {…}” to
“form > #wrap {…}”
I spent 2 hours trying to get this working until i read that post …thanks IKarlik
Cheers
Ed
Can you please tell me the css for #foot
I’m trying to make a banner that covers 100% width at the bottom of page and I’m having some trouble.
When I try to put it inside the footer it appears at the top of the page.
What am I doing wrong?
Thank you
Excellent. I’ve had countless solutions to this problem over the years and until now I’ve never found one that just *works*.
This one works great for me, and I’m pretty sure I’ll be using it in 95% of all sites from now on.
Thanks!!!
I tested it in Firefox 3.5 through the CSS Sticky Footer website and it works!
Congrats! And thank you.
@Paul O’Brien, thank you for your July 23rd post, it was the solution to my problem of the code being correct but a vertical scroll bar appearing when there was little content on the page.
If anyone else has the same problem, and you are sure your code is right, it might be helpful to know that your footer’s height means a sum of its actual pixel height, and any top or bottom padding it may have (and the height of a border like Jim’s case). Thanks again Paul.
Perhaps this could be mentioned in the CSS Sticky Footer instructions?
I just can’t get this to work. Like so many others, my footer is pushed way lower than the screen, so I have vertical scrollbars. There is very little content on the page. I have followed the directions to a T, making sure there is no top or bottom margins set anywhere - still cant get it to work. what solutions are folks using to fix this specific problem?
Awesome code snippet, much cleaner than some of the others I’ve run across. I do have a question about it, though. What is up with this line:
body > #wrap {height: auto; min-height: 100%;}
What is the right carrot for, I don’t understand what it’s purpose. Can someone enlighten me?
Just wondering. You keep mentioning that margins will mess up the layout and I was wondering if you mean that with this method you cannot use margins at all for vertical spacing?
If so, how do this many people find it useful? Or is there only a specific instance where you can’t use margins?
For example in my content, can I have margins between paragraphs? or would I have to use padding?
Thanks.
@Victor - without your code we can’t help :). Just go back to the demo in the article and compare what you have with what is in your page. It’s so easy it can’t fail to work unless you deviate from the example
@Jason: The right arrow is the child selector (combinator) which will select a direct child of the element concerned. It is used as a hack to hide code from ie6 as it doesn’t understand the child selector. I suggest however that you don’t use this method because it can fail in IE7 and use the 100% method I posted somewhere above.
#wrap{min-height:100%;}
* html #wrap{height:100%}
@Ian Storm: You misunderstand the problem with margins.:) There are no problems with margins inside the 100% high container (as long as they don’t stick out of the top and bottom of the container). The advice referred to margins on the actual 100% high container itself.
If you apply margins to the container itself (e.g. to move it away from the body) then the container will no longer be 100% high but will be 100% high + margins and therefore never fit in the initial viewport.
Margin on elements inside the container are fine (as long as you avoid collapsing margins on the first and last elements in your page).
Thank you very much for the quick response. Sounds perfect, and I will be installing it shortly!
Hi Paul
Yeah, your right, without the code u cant do anything.
But i forgot to writr again telling that i solved trh problem, i had a wrong value on the body.
Its working and thanks for this trick
u can see it working @ http://www.vitorneves.com and also on my 1st wordpress template @ http://webappsdepot.vitorneves.com
Regards
I’ve found another issue with this fix. This is definitely an issue because it evens occurs on your implementation Stu.
In IE6 if you decrease the width of the page to be less than the minimum then the horizontal scrollbar appears. This overlays the viewport and thus a vertical scrollbar appears for scrolling the small area stolen by the vertical scrollbar.
I’ve got this to work but I am facing a bit of a problem in the main div.
I have two columns, one menu on the left at 170px wide and next to it I have a content div.
I want the content div to expand 100% in height and width according to the window size, however when ever I set the width at 100% it div overflow to right causing a scroll bar to see the rest of the screen. and the height just gets ignored.
is there any way to accomplish this?
this is my html
I have sideMenu and content floating left with sideMenu’s left property set to 0px and it’s width to 170px. The content div has the left property set to 170px which is the sideMenu’s width.
Thanks
Hi,
Normally I use this code to center a div:
#wrapcentering
{
position: absolute;
width: 1000px;
left: 50%;
margin-left: -500px;
top: 0px;
}
When I used Ryanfait’s sticky footer, I used this code to center content and it worked perfectly. The only thing I had to change, as he mentioned himself, was margin to padding if the footer didn’t work.
Now I wanted to try this new sticky footer and I wanted to center my whole content. When I use this code, the footer is not sticky anymore. So I tried to change the margin to padding from the sticky code, and then it worked, but only in IE.
Is there a way to center the whole content using this footer for al browsers?
Thanks.
@Sam,
I think using position:absolute may be screwing it up.
Try the following:
#wrapcentering
{
margin-left: auto;
margin-right: auto;
width: 1000px;
}
That’s it!
I use it on all my sites for centring the main wrap and have no issues with this Sticky Footer technique in any browser. Hope that helps.
Ok, thanks! I’ll try this one…
BTW: Great job!
Should the footer on the “How to Use the Sticky Footer Code” page also be sticky? If yes, then something on that page went wrong as in Firefox 3.0.14 on Ubuntu Hardy the footer is way down at the end of that page… :/
@Lars, that is how it is supposed to work, on long content pages it goes to the bottom, but on short content pages it goes to bottom of browser window instead of floating up higher than bottom of window.
@Stever: ah ok, thanks for the fast clarifying. Do you have an example of how to get the footer to always stick at the end of the browser window no matter how long the scrollable content is? This was a huge issue I could only solve with the aid JavaScript in IE6 so far…
While using this solution i had a problem with the footer creeping up in IE8.
While debugging I added the css:
#footer {
filter: alpha(opacity:50);
}
to try to take a screen shot and figure out exactly how much i was overlapping.
Much to my puzzlement this fixed the problem. I edited IE’s crappy proprietary CSS to set the opacity to 100% and called that the end of a very long day.
It’s a total hack but it might help if other people are having the same problem.
@Justin, interesting! This solution was published just before IE8 was released and others have mentioned problems with IE8. Your solution, while a total hack, might just do the trick.
IE8 can be fixed by adding display:table to the outer as I mentioned in my previous posts.
Depending on what your main wrapper is called you can use something like this.
#outer {height:100%;display:table;}
That will make the footer work correctly in IE8.
The code above should be supplied only to IE8 using conditional comments though (The comment system removed the actual code I posted
)
Hi, thanks for nice solution. There’s only one thing that interests me - why there’s a position: relative; on the #footer? Everything seems to be working even w/o it in all major browsers. Thanks for clearing this up.
thank you so much!! saved me so much time trying to do it myself!
I use the Ajax Tabs Content script by Dynamic Drive and Ryan Fait’s solution destroys some of the formatting. This solution works perfectly!
never mind, fixed it. extra div tag was closing my wrap too early. doh.
Hi,
I really like the solution. I always used float based layouts, and it is working perfectly. But now I have to use an absoulte positioned div within the #main, where I load different content in, so the height of the div differs.
Is there a way to avoid the absolute positioned div to overlap the footer without giving #main a fixed height?
Dear Stever, or anyone who can help:
I have attempted to implement your lovely and indispensable solution here:
http://www.rentlarasbrain.com
It works splendidly on IE 7 & Chrome, but I have a gap at the bottom in the latest Firefox (3.5+ or so). My code validates, I’ve ruthless slashed away any vertical padding or margins, but still it is not behaving. Any advice?
My css is here:
http://www.rentlarasbrain.com/css/main.css
I have used position: relative; a couple times, to get around the need for margins to put things in the right spot. I hope that isn’t what is breaking it. :-/
I tried sticking duct tape on my screen, but the footer is still floating..!! CAN SOMEBODY HELP ME???
If you want a short footer, like say 15px, and have little (or no) content on the page, it most definitely does not work in Safari or any recent version of WebKit. Neither does Fait’s.
Man oh Man….
You can’t imagin’ how glad i am with this sticky footer…
I’m one of those people who try’s to do it all by himself. That made me a frustrated fool last month.
Even tryed the .push version, all did’nt seem to work and was “breaking up” my layout. But now i really found it after hours and hours of fooling around.
There where a couple of things i did wrong that maybe helpfull to others to mension:
-if you’re using more divs for layout reasons, EVERTHING should go in the main div
-The footer needs to be outside the wrapper.
“Oke?!”, you would say, “So what’s new?” well this arse did it wrong and spend hours searching for wrong anwsers…
This method works great at the end.
The .push div method still does’nt work in my layout.
THANKS A BUNCH!
Greats from the Netherlands!
@Nathan Duran : show me where it isn’t working in Safari and I’ll fix it for you
perfect, but… what´s the solution to ie6 “margin:0 auto” center site?
i have the solution about ie6 margin=”0 auto”. i have put
#footer {
position: relative;
margin-top: -85px!important;
in a “if IE 6″
thanks again
I been trying to figure this out for a couple of days now. Sorry about the multiple posts, html code would not publish.
I’ve got the following:
div id=’wrap’
div id=’main’ class=’clearfix’
div id=’content’
div id=’news’ /div
iframe id=’dynamicContent’ /iframe
/div
div id=’sidemenu’
/div
/div
/div
Within the ‘Content’ div I have two items, the news div is displayed on load and when a menu item is clicked it gets displayed within the iframe and js hides the news div.
The problem I am facing is overflow:auto within the content div, the iframe handles it fine but the news div does not. The only place I can get the overflow:auto to work is by putting it in the Content div and then it breaks.
On page load the content div is blank and then if you resize the browser window it shows the news div. if i remove the overflow:auto from the content div it shows as it should.
Any ideas?
oh by the way, this only breaks in IE, FF works just fine.
i think i fixed it.
i changed:
.clearfix
{
display: inline-block;
}
to
.clearfix
{
display: block;
}
and now the overflow works in the content div as it should in IE.
Hey there. This has been racking my head, since I think I have it right. The footer is in fact sticking as expected, but I can’t seem to get rid of the vertical scroll bar. I created a test page to see if it was the content within #main, but even on a blank page the scroll bar is there, but yet not on the example page, so I am in error somewhere.
here’s a link: http://tr.im/FbFf
It’s funny how long I’ve gone without this being necessary, but now that I need it, I’m losing my mind. ha.
Thanks in advance,
Rich
@Rich Stats: remove the 5px bottom padding from the p element in the footer as that makes it too big.
#footer p{padding:20px 0 0;}
thanks paul. wow, that was a quick response I really appreciate it.
Rich
Is there anything special that needs to be to get this to work in IE6?
My footer does not sit flush on the bottom, it is about 3 pixels up.
Also, I have a left menu and content area, in the content area I have an iframe that will not adhear to size of it’s parent div, it goes over on the right and bottom.
Any ideas?
Thanks for this- it works great!
It’s been mentioned a couple of times above for asp.net integration, but just to reiterate and consolidate:
To make this work correctly in an asp.net page add the ‘form’ selector to the first, and replace ‘body’ with ‘form’ in the second.
html, form, body, #wrap {
height: 100%;
}
form > #wrap {
height: auto; min-height: 100%;
}
Hi,
Thanks for this great solution! I only have one problem and I can’t get it fixed…
Pleas visit my website. When you make the Windows smaller (or when you view the website on a smaller screen, the content of the sidebar is invisible behind the footer. What can I do about this?
Willem
I can’t get this to cooperate with IE6, it’s working fine in ie7,8, FF but not IE6. The footer is pushed up a few pixels from the bottom. Any ideas what could be causing it?
@Danny: Your footer is probably higher than you think it is because IE6 will expand all elements to accommodate its content.
Make sure the footer is the exact height you need (give it a specific height) and then hide any overflow from IE6 with overflow :hidden in case you have margins or content in the inner footer content that are poking out.
Thanks Paul, setting the height did the trick but now I’m facing another problem.
In IE6 the scroll bars don’t appear until the window is half way up the content.
In IE7+ and FF the scroll bars appear when they should but the footer keeps going all the up to the header. It doesn’t stop at the point where the content starts like it does in the test page shown in this site, it stops when it reaches the header.
@Danny: Have you cleared any floats properly?
Check the code is valid and that there isn’t a missing tag somewhere.
Other than that we’d need to see the page to debug further
Thanks Paul, I varified that the code is valid. you cant see the page because it is an intranet app.
I will paste the css here for you to see.
The divs are set like this:
[div id=’wrap’]
[div id=’divHeader’][/div]
[div id=’main’ class=’clearfix’]
[div id=’divSideMenu’][/div]
[div id=’divContent’]
[div id=’homeascx’]
[div id=’newscontainer]
[div id=’divNewsMain’][/div]
[div id=’EvTitle’][/div]
[/div] - end newscontainer
[/div] - end homeascx
[/div] - end divContent
[/div] - end main
[/div] - end wrap
[div id=’footer’][/div]
Here is the CSS:
/* BEGIN WEB PAGE STRUCTURE CSS*/
*
{
margin: 0;
padding:0;
}
html, body, form, #wrap {
height: 100%;
overflow:hidden;
}
form > #wrap
{
height: auto;
min-height: 100%;
}
#main {
padding-bottom: 20px;
height:100%;
} /* must be same height as the footer */
* html #main
{
height:100%;
padding-bottom: 20px;
}
#footer
{
position: relative;
margin-top: -20px; /* negative value of footer height */
height: 20px;
clear:both;
overflow:hidden;
}
.clearfix:after
{
content: “.”;
display: block;
height: 0px;
clear: both;
visibility: hidden;
}
.clearfix
{
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix
{
height: 1%;
}
.clearfix {display: block;}
/* End hide from IE-mac */
#divHeader
{
width:100%;
height:100px;
clear:both;
}
#divSideMenu
{
position:absolute;
top: 100px;
width: 180px;
bottom:20px;
height:100%;
overflow: auto;
background-color: #666666;
}
#divContent
{
overflow: auto;
position: absolute;
top: 100px;
left: 180px;
right: 0px;
bottom: 20px;
}
#homeascx
{
width:800px;
height:525px;
}
Hi Danny,
I’m afraid you can’t use absolute positioning in that way because absolute elements are removed from the flow and will just run roughshod over everything else. They don’t care about anything else on the page and any in-flow elements like the footer will just rise over them as thought they aren’t there.
If you want two columns you will need to float the columns and then clear them to regain the flow.
Absolute positioning should be avoided for structural columns in a layout like this (or in any layout where you need a footer under both columns).
Float the columns and then make sure you clear them.
Note that you cannot use 100% height in inner elements because that wont work and if it did it would mean your layout cannot grow. You can’t add padding to a 100% element either because then it would be bigger than 100% and that means it would be too big.
Hope that makes sense
Man ! the french translation sucks. Sounds like it has been google translated like shit.
Anyway, i wont use duct tape anymore.
thanks a lot !
Can someone take a look at this site and maybe shed some light on what I am doing incorrectly on the home page?
It seems that on all of the other pages within the site, the footer is sticking to the bottom as expected. But for some reason I can’t get it working on the home page. I’m sure it’s something simple but I just can’t figure it out. Here is the url:
http://www.corvairflair.com/sarah-lamb/
@Mike - the footer is on the bottom :). it’s 200px high and sits on the bottom. Change the height if you don’t want it so tall and then change the negative margins and padding to compensate (as mentioned in the article).
Thank you, finally one that really works!
Incorporated into my CSS and code and it worked like a charm first attempt, no fussing with sloppy code.
This solution seems to work great for liquid layouts but what about fixed width layouts?
My footer will not display properly if it is outside of the wrap (#maincontainer in this case)
Any solutions? For now I’ve just stuck the footer back inside the wrap until I can do more research.
It works like a charm…I have only one problem. When the content is longer than the page and I scroll down to the footer, the content goes through the footer (behind it) to the bottom of the page. How can I solve this? (for example: visit: http://www.willembosma.nl/?p=wie-is-willem).
@Willem: You don’t seem to have added the padding-bottom needed to preserve the footer space.
The element called #mainvp should have 150px padding bottom.
#mainvp {
width: 900px;
overflow: hidden;
font-family: verdana;
font-size:13px;
line-height: 1.5;
margin-top:15px;
color:#646464;
text-align:justify;
padding-bottom:150px;
}
Does it work in HTML 5 ?
I can’t get it to work. I haven’t done any webdesign in nearly five years. I gave up because of god damn IE.
Either way, I did some looking around and found the YUI Grids, however, cannot get this technique to work with it. I even tried to search for some answers, but have as of yet to find anything useful. I’ve got on that always at the bottom of the viewport, but bottom of the page? Seems impossible.
If anyone has some pointers, I stuck the page on a fee hoster, it’s the link.
This is just for me to get back into it rather than being anything specific.
hey stever!,
after seeing late 2009, i finally decided to implement it, but after reading sum of the blogs here i had a question:
is the ie8 problem resolved (i.e. updated on the site where you download it - or do i need to implement more fixes?).
i’m making a site for someone, and i was hoping that it would be at least a bit futureproof for 2-3 yrs?
cheers, alex.
@alex, things on the site do need an overhaul to ensure its ie8 friendly. Not sure when I may get around to that though, current work load is HEAVY.
no probs mate, thanks for the quick reply
I have used the sticky footer and it works brilliantly, but I need to add a background image that sits on the top of the footer that moves up and down with the footer but the background image stops under any content on the page. I’ve tried several ways but cannot get it to work.
hi, thanks for the sticky footer, mostly working great, but not in IE8 - footer is heading off the the right col side bar for some reason in IE8… I’ve done some research and tried a few things, but no luck yet - any ideas?
can send you some code/web address if needed.
Thanks!
@Larraine:Does the image above the footer slide under the content above or stop short of it?
If it slides underneath then just absolutely position it from within the footer itself (position:relative on the footer as a stacking context)and then adjust the z-indexes accordingly so that the image goes under the content above.
If you want content to stop above the footer image then just increase the height of the footer itself and use the top part for the image.
@Anthony: IE8 can be made to work using display;table:
#wrap{
display:table;
height:100%;
}
@Anthony: The code above needs to be within conditional comments just for ie8 (the forum code stripped it from my post above).
Thanks Paul. I have tried this and it still doesn’t work…? perhaps i didn’t do it properly (still fairly new at it!)? its a 2 col layout - maybe its something else in the style throwing it out… i’ve posted the website. let me know if you have any more ideas… Thanks in advance!!
Paul - sorry, here is the website: http://ee.teenstreet.org.au/index.php/site/index_new/ Thanks again!
I think i’ve found the problem. don’t think its a css/sticky footer thing, but IE8 doesn’t seem to like a form input, so i will work on that first and hopefully that fixes it! thanks for the tips though.
@anthony: You need th fix the html first as you have embedded another document in your page.
At lines 43 - 62 you have another doctype and head section which should not be there. Most of that code should be in the head of the document (without the extra doctpe and head tags etc.
Then at line 85 - 89 you have some closing body and html tags that shouldn’t be there either.
It looks as though you copied a whole page into the middle of your document rather than the html that was actually required.
If you tidy that up and validate your page then the code I mentioned before will work but you will need it to put it in conditional comments for IE8 only and also give it more weight (as shown below).
body > #wrap{display:table;height:100%}
I think I found two ways to break it (only tested in FF3.5 and Chrome 4.whatever):
1) I had a sidebar with absolute positioning. The sidebar would elongate to reveal a contact form when a link was clicked, causing it to go off the bottom of the page. It went _through_ the footer, rather than pushing it down. The footer maintained its original position with the sidebar behind it. I fixed this by rearranging my CSS and using relative positioning for the sidebar instead.
2) Setting a line-height in the footer alway created some extra space out the bottom of the page, even when the line-height was 20px and the height of the footer was 50px.
@Chadoh:
1) absolute elements are removed from the flow and cannot be used as columns when you want a footer to span all columns.
2)Sounds like you are doing something wrong as the content will be contained within the height that you set. Set overflow:hidden if you have content greater than you have allowed for.
Hi
I am having problems with the sticky footer in ie6. it is sticking at the bottom of the window and not recognising the content above it.
following is my code - the negative margin in the main div does not seem to affect the footer.
Any help would be great
#main {
background: #FFF;
margin-right:0;
margin-top: -7px;
margin-bottom: 0;
overflow:hidden;
width:990px;
padding-bottom: 100px;
}
#wrap {
margin: 0 auto;
width: 990px;
height: 100%;
}
body > #wrap{
height: auto !important;
min-height: 100%;
}
#footer_wrapper {
background: url(../images/footer.png) repeat;
margin: -100px 0 0 0;
height: 100px;
clear:both;
position:relative;
}
.clearfix:after {
content: “.”;
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
/* End hide from IE-mac */
Paul, thanks again for the tips. yes there was some messy html in there and am fixing it all up slowly! I’m using expression engine and had embedded a template within another - have since cleaned it up. Sticky footer seems to be working fine in IE8 now even with out the display:table, but will keep it in mind if any probs pop up! Thanks.
Can somebody help me. I got it that the footer is always in the bottom. But when it has to get pushed away because of the content, it doesnt go smoothly, but its like bamm. and the footer is gone. how can i fix this?
@Bas: We would need to see code as that is not a behaviour of the footer technique. It’s likely your structure is incorrect n some way but without code it’s impossible to tell.
Shadowbox.init({
language: “nl”,
players: [”qt”, “img”]
});
$(document).ready(
function(){
$(’#slide’).innerfade({
animationtype: ‘fade’,
speed: 3000,
timeout: 6000,
type: ‘random_start’,
containerheight: ‘auto’
});
}
);
home
services
portfolio
contact
setPage()
(c) Mystic Solutions |
home
services
portfolio
contact
inloggen
you need the css too?
Shadowbox.init({
language: “nl”,
players: [”qt”, “img”]
});
$(document).ready(
function(){
$(’#slide’).innerfade({
animationtype: ‘fade’,
speed: 3000,
timeout: 6000,
type: ‘random_start’,
containerheight: ‘auto’
});
}
);
home
services
portfolio
contact
setPage()
(c) Mystic Solutions |
home
services
portfolio
contact
inloggen
Damn xD
i post the css.
* {margin:0;padding:0;}
body{
background-image: url(’../images/bg_alles.png’);
margin: 0 auto;
font-family: verdana;
font-size: 10pt;
color: #ededed;
overflow-y: scroll;
}
a{
text-decoration: none;
border: none;
}
a:focus{
outline: none;
}
a:link {color:#ededed} /* unvisited link */
a:visited {color:#ededed} /* visited link */
a:hover {color: white} /* mouse over link */
a:active {color:#ededed} /* selected link */
img{
border: none;
}
h1{
font-family: Verdana;
font-size: 18pt;
color: white;
margin-bottom: 0px;
margin-top: 0px;
padding-top: 10px;
text-align: right;
font-weight: 100;
}
h2{
font-family: Verdana;
font-size: 18pt;
color: white;
float: left;
margin-bottom: 0px;
margin-top: 0px;
padding-top: 10px;
text-align: left;
font-weight: 100;
width: 400px;
}
#top{
background-image: url(’../images/bg_top.png’);
height: 127px;
width: 100%;
}
#top_schaduw{
background-image: url(’../images/schaduw_menu.png’);
height: 25px;
width: 100%;
}
#top_960{
width: 960px;
height: auto;
margin: 0 auto;
}
#logo{
background-image: url(’../images/logo.png’);
height: 126px;
width: 185px;
margin-left: 75px;
float: left;
}
#menu{
background: url(’../images/bg_menu2.png’);
background-position: right;
background-repeat: no-repeat;
float: right;
list-style: none;
width: 398px;
height: 126px;
margin: 0px;
}
#menu li{
background: url(’../images/bg_menu.png’);
background-repeat: no-repeat;
width: 99px;
height: 126px;
float: left;
text-align: center;
}
#menu a{
display: block;
text-decoration: none;
height: 30px;
color: #b8b8b8;
padding-top: 99px;
border: none;
}
#menu a:hover{
color: white;
}
#menu .current{
color: white;
}
#banner{
background-image: url(’../images/bg_banner.png’);
width: 960px;
height: 245px;
background-repeat: no-repeat;
margin: 0 auto;
}
#slide{
margin: 0 auto;
width: 837px;
padding-top: 27px;
padding-right: 5px;
list-style: none;
}
#content_schaduw_boven{
background-image: url(’../images/schaduw_content_boven.png’);
width: 100%;
height: 25px;
}
#content_schaduw_onder{
background-image: url(’../images/schaduw_content_onder.png’);
background-repeat: repeat-x;
width: 100%;
height: 25px;
float: left;
}
#content{
background-image: url(’../images/bg_content.png’);
background-repeat: repeat-x;
float: left;
width: 100%;
min-height: 300px;
background-color: #838282;
padding-bottom: 10px;
}
#content_tekst{
width: 920px;
height: auto;
margin: 0 auto;
text-align: justify;
}
#tekst_welkom{
width: 600px;
float: left;
}
#tekst_update{
width: 278px;
float: left;
text-align: justify;
}
#tekst_update img{
margin-top: 5px;
margin-bottom: 5px;
}
#tekst_update img:hover{
margin-top: 5px;
margin-bottom: 5px;
filter:alpha(opacity=100);
-moz-opacity: 1.0;
opacity: 1.0;
}
#tekst_contact{
width: 960px;
height: auto;
}
#tekst_contact .collum1{
width: 600px;
float: left;
}
#tekst_contact .collum2{
width: 278px;
float: left;
}
#tekst_contact .form{
width: 278px;
float: left;
}
#content_lijn{
background-image: url(’../images/content_lijn.png’);
width: 1px;
height: 422px;
float: left;
margin-left: 20px;
margin-right: 20px;
}
html, body, #wrap {
height: 100%;
}
body > #wrap {height: auto; min-height: 100%;}
#content_schaduw_onder{
padding-bottom: 19px;} /* must be same height as the footer */
#footer {
position: relative;
margin-top: -19px; /* negative value of footer height */
height: 19px;
clear: both;
width: 100%;
}
#footer a:link {color:#b8b8b8} /* unvisited link */
#footer a:visited {color:#b8b8b8} /* visited link */
#footer a:hover {color: white} /* mouse over link */
#footer a:active {color:#b8b8b8} /* selected link */
.footer{
height: 19px;
background-image: url(’../images/bg_footer.png’);
width: 100%;
}
.footer_tekst{
color: #b8b8b8;
width: 960px;
text-align: right;
margin: 0 auto;
font-size: 8pt;
padding-top: 3px;
}
.clearfix:after {
content: “.”;
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix { height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
textarea{
text-align: left top;
}
If you need the html just give me a call
@Bas;
a) Does this happen after some dynamic content has been actioned or does it happen all the time?
b) This looks bad
#content_lijn{
background-image: url(’../images/content_lijn.png’);
width: 1px;
height: 422px;
float: left;
margin-left: 20px;
margin-right: 20px;
}
Looks like you have a 422px high x 1px wide divider that could possible be dropping suddenly and pushing your footer another 422px down the page. Try removing that element and test again.
As a rule of thumb you would never float a 1px divider like that but wrap the content in a container and apply the image to a parent container instead.
Obviously I can’t tell how your html is arranged so there may indeed be an error somewhere else if the above is not related and the html would be needed.
So I ask again… has anyone gotten this footer working with YUI Grid layouts?
It always happens. And i really have to make that div that way. And thats not the problem. Because i deleted it, but it still is the same.
@Bas: I assume we are talking about the site linked to under your name (Mystic media).
What browser are you having problems in as I don’t see the effect you mention. the content isn’t near the footer because you have put a 300px min-height on the content anyway.
I can see IE6 is completely broken but I guess you are not supporting that browser.
IE7 has double scrollbars on the window because you set the body element to scroll. Move that to html instead.
html{overflow-y:scroll}
However I can’t see this sudden jump in the footer effect you mentioned. What page does this happen on and what do I have to do to make it happen?
Hi im confused not hard to do i admit lol when i just copied the html code and the css code as is it looks fine but appears as boxes which are not full width where am i going wrong ?
Fantastic, it was really satisfying to see this work in my own code - thanks for sharing this.
Its in Safari. in firefox its working great. And i am still developing the site. So IE comes at last
@bas: Ok I can see the problem in Safari and it’s caused by the 100% float that’s holding the shadow at the bottom.
If an element is 100% wide it doesn’t need to be floated in most cases (and may indeed cause some issues) so remove the float but add clear:both and then you can remove the clearfix class from that div also.
#content_schaduw_onder {
position: relative;
background-image: url(’../images/schaduw_content_onder.png’);
background-repeat: repeat-x;
width: 100%;
height: 25px;
padding-bottom: 19px;
/*float: left;*/
clear:both;
}
div id=”content_schaduw_onder”
Hi, can someone please take a look at my website (http://awrs.webhop.net/test) and let me know how to fix that gap? It is fine on pages with long content.
Hello, Stever!
May I be able to use your code on my website that I’m building for commercial purposes?
Yes you can - Stever
Thanks! That was it! It works great now!
Great work, works perfectly, I’m curious though, if anyone has any ideas on how to code the height of the footer to be a bit more variable. I’m creating a wordpress theme where updates will be dynamically added to the footer, which means the height will change over time. Any thoughts
Hi there, trying to make this solution standard on all sites that I hope to create, however I’m having some issues with putting a shadow on the outside (border) of the wrap. If I want to have a shadow repeat along the y-axis from top to bottom of the page, can I simply add another div around the entire sticky footer code?
Hi,
I am facing a problem while using this code in IE6. I have introduced a according (JQuery) in my page. So while loading the page for the first time its working fine. But when click on the according the page height is inclreasing so the footer remains there.
Please suggest me.
Thanks
I’m having trouble implementing the Sticky-Footer. At first it worked, but once I put a container inside of a container the footer moved up the page. You can see the page at…
http://www.rls.net/mockup/Test.html
I’m using “min-height: 620px” for the center container.
Any ideas as to what I am doing wrong?
hmmm, i can’t get it to work in Wordpress. In wich php-page do put the code? (index.php or page.php)
many thanx in advance!
I’m trying to implement with Blueprint…and the sample with the long content fails in Safari and Firefox: http://cfc.kizzx2.com/blueprint-sticky-footer-2/sample-long.html
What’s up?
The short sample works, but not the long. I can’t seem to make the long one work either
hi,
i am using this code in my site designing but its not working, please suggest me something.
#header
{
position: absolute; margin-top:15px;
left: 5px;
padding: 10px;
height: 42px;
width: 100%;
border: 1px thin #0099FF;
}
#pic{
position: absolute;
left: 15px;
margin-top: 72px;
height: 179px;
width: 621px;
border: 1px thin #0099FF;
}
#text
{
position: absolute;
left: 15px;
margin-top: 250px;
height: 37px;
width: 621px;
border:medium #0099FF;
text-align: left;
text color:#9A0214;
padding:5px;
}
h1 {
font-size: 18px;
color: #990000;
font-weight: bold;
text-align: left;
}
h2 {
font-size: 15px;
color: #3333FF;
font-weight: bold;
}
h3 {
font-size: 18px;
color: #000000
font-weight: bold;
}
#left {
padding: 3px;
position: absolute;
left: 15px;
margin-top: 290px;
width: 299px;
height: 150px;
size: 8px;
border: 2px solid #0099FF;
}
#center {
padding: 3px;
position: absolute;
margin-top: 290px;
left: 330px;
height: 150px;
width: 298px;
size: 8px;
border: 2px solid #0099FF;
}
#left1 {
padding: 3px;
position: absolute;
left: 15px;
margin-top: 456px;
width: 299px;
height: 150px;
size: 8px;
border: 2px solid #0099FF;
}
#center1 {
padding: 3px;
position: absolute;
margin-top: 456px;
left: 330px;
height: 150px;
width: 298px;
size: 8px;
border: 2px solid #0099FF;
}
ul {
list-style-image: url(images/icon-arrow-dred.gif);
}
#sidebar {
position: absolute;
padding: 3px;
left: 675px;
margin-top: 73px;
width: 300px;
height: 374px;
border: 2px thin #0099FF;
text color:#990000;
size: 8px;
}
#topnav {
position: absolute;
margin-top: 15px;
left: 675px;
font-size: 14px;
height: 42px;
width: 533px;
}
#textside
{
background-color:#E0E0E0;
}
#content {
padding: 3px;
position: absolute;
left: 15px;
margin-top: 290px;
width: 612px;
border: 2px solid #0099FF;
height:auto;
padding-bottom: 3em;
}
#text li {
float:left;
padding:2px;
}
html, body, #wrap {height: 100%;}
body > #wrap {height: auto; min-height: 100%;}
#main {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;}
.clearfix:after {content: “.”;
display: block;
height: 0;
clear: both;
visibility: hidden;}
.clearfix {display: inline-block;}
/* Hides from IE-mac \*/
* html .clearfix { height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
First of all thank you for the very informative site. It helped me get my footer onto the actual page because it was sitting below the browser window in the first place.
However, after changing it my footer now sits slightly above the bottom of the page (almost double the height of my footer) with excess space underneath.
I checked all of my margins and I dont have any left besides those given in the tutorial.
Also, the text that i have in my footer is sitting sort of above the footer itself, even though it is contained in the footer div.
Sorry if my question has already been answered…I scanned the comments quickly but couldnt find much to help me.
Thanks!
I forgot to say that my footer consists of an image that repeats in the x-axis…dont know if that matters or helps the situation
I’m trying to use your sticky footer with my page here: http://goo.gl/N3Vu
Seems if I set my footer div to “relative” then it sticks on the top of my window, so right now it’s set to “absolute”, but as you can see, it’s rolling under my content layer. I’m using z-index throughout the page (and maybe that’s what’s all messed-up).
I would really appreciate it if someone could advise… been spending too much time on this. I’m *this* close to just saying “f it, I’m just going to use a table”
[edit] Correction: the footer is overlapping the content.
I’m having the same problem as Chris who posted at the very beginning of the comments. In FF, Chrome, Safari & IE8 I’m getting a gap under my footer, but only when the content expands and causes scrollbars in the browser. (IE7 is fine for some reason, IE6 not supported.)
I can’t figure it out and have all margins zeroed out:
http://airhart.jasonnarciso.com
Any help is greatly appreciated!
I managed to get this work, but there is one tiny problem I think. Visit http://www.keesblok.nl and you will see on every page that they scroll vertically a few pixels. I know that this has something to do with margins and paddings, but I can’t find it. Can someone help me with this?
@Willem - If you have a scroll then the content in your footer is too big and poking out somewhere. Hide the overflow to see if that fixes it.
#footer {overflow:hidden}
Can anyone please give me some assistance?
I have a container inside of a container and the footer moves up the page. You can see the page at…
http://www.rls.net/mockup/Test.html
Any ideas as to what I am doing wrong? Any assistance would be greatly appreciated.
I apologize profusely to all those who have posted comments in the past couple months and I’ve neglected to approve your comments. I’ve been very very busy.
I’m also about to publish a new version of the Sticky Footer code. One that works for ie8, and fixes an Opera bug, using some of the comments posted above, and some other tricks I found.
A big public thank you to Paul O’Brien who’s given lots of help to people here.
New version about to go live in the next week or so.
@Randy - You have used absolute positioning for the columns which means they are removed from the flow and there is no way that a footer (even a sticky footer) can sit at the bottom of all columns. It’s just impossible.
Absolute positioning shouldn’t be used for columns and you should float the columns instead.
Something roughly like this:
* html #page_container{height:1000%}
/* MAIN WRAPPER */
#main_wrapper {
float:left;
min-height:620px;
margin-left: 10px;
width: 790px;
padding: 0px 0px;
/* margin: 10px 0px;*/
background: #66FF66;
display:inline;
}
#left_window {
min-height:620px;
float:left;
width: 300px;
background: #66CCFF;
}
#right_window {
float:right;
width: 460px;
padding: 0 10px;
background: #CC99FF;
}
You will of course need to add the clearfix class to the parents of the floats to allow the backgrounds to extend.
@Addy - You can’t use absolute positioning for your columns they will need to be floated. See my comments above to Randy.
@Paul - Thanks! That worked wonders. Except now I notice that there is a white horizontal space at the very end of the page. Any ideas as to what could cause that?
http://www.rls.net/mockup/Test.html
@Stever: What about being usable with YUI Grids?
@Randy - take out the dot from within the quotation marks in the content property.
/* CLEAR FIX */
.clearfix:after {content: ” “;
display: block;
height: 0;
clear: both;
visibility: hidden;}
Also change this line:
* html, #page_container {height: 100%;}
to this instead:
* html #page_container {height: 100%;}
@Matthew: You should be able to use it on grid pages but you may have to create a wrapper to hold the whole page and to control the height. As long as you imitate the sticky footer structure correctly it should work.
@Paul - Works like a charm now! Thanks much!!!
Hello,
First of all I’d like to say thank you for share this technique, and good job creating it.
I have been trying to use it on a Wordpress theme I am developing, it works fine except that on pages with little or no content there is still a scrollbar. I tried to add overflow: hidden to the #footer, but that didn’t fix the problem…
Here is the page in question:
http://uselessgeek.com/youjiii/wordpress/contact-us/
and here is the css I use for the page:
http://uselessgeek.com/youjiii/wordpress/wp-content/themes/test1/style.css
Does anyone know what might be causing the scrollbar to appear please?
@Paul: I tried that originally and it never worked :/
@Matthew - I’d need to see the page you tried it on to see where you went wrong.:)
The technique is simple but it has to be right and in the right structure and applied correctly.
As shown by some of the other posters above who have tried using a sticky footer on absolute elements there are of course some things that can’t be done because they have the wrong set up to start with.
@Matthew, I’m not familiar with YUI grids, so I can’t answer that.
Working with any pre-built css formatting you would really need to under stand that format in and out and how and where to alter it ti suit your needs.
Hello, I tried using this technique and I got the extra margin at the bottom to make room for the footer, but the footer itself is still floating up at the top of the page. I’m really stumped
(Currently building the site on localhost so it’s not on the web at the moment.)
sorry but I am new to programming but is there anything wrong with this simple css code for puting footer at bottom?
{
position:fixed;
bottom:0px;
height: 100px;
background-color: #0FC;
width: 950px;
left: 50%; margin: 0 0 0 -475px
}
I just put the html div tag at bottom of body and it works like a charm. Stays put on scrolling. I’m obviously missing something.
@Paul, click my name. The only thing I’ve managed is to get a footer to constantly stick to the bottom (always on screen).
At the moment, I’ve sort of just learnt to live with it.
@Matthew: On that page you would just need to move the footer out of the parent wrapper (#doc3) so that it sits outside the closing tag of #doc3.
Then apply the usual sticky footer code:
#ft {
background-color: green;
text-align: right;
height: 4.615em;
margin-top:-4.615em;
position:relative;
}
html, body {height:100%;}
#doc3 {min-height:100%}
* html #doc3 {height:100%}
#bd{padding-bottom:4.615em}
#hd{padding:1px 0 0}
Thanks paul
This is great but I’m having a problem. My footer is sticking to the bottom like it should, but for some reason there’s a big gap between it and the content, so you actually have to scroll down to see it’s there. Can be seen on the website I’ve linked to. I have a feeling I’ve made a stupid mistake somewhere…
Any help would be greatly appreciated!
@Jenny
your topbox, header and shadow divs are sitting outside the wrapper div. Only your footer should be outside the wrapper.
Your footer is pusged lower by the heights of those other divs sitting above the wrapper. Wrapper is set to 100%, then footer gets sucked up under by negative margin. So adding anything else outside of wrapper makes your total page height larger than 100%.
@Aziz: The footer in your page is 250px high plus a 1px border so the negative margin on the footer needs to be 251px.
[…] old post for the original version has gotten nearly 300 comments so far. Clearly my most popular post on this blog. I am however […]
Aha! Fixed it
Thank you so much!
Question for aspx developers … I have applied this to my masterpage for my web application and it works great for all the browsers.
The only issue is that I am getting a scroll bar on the window when there shouldn’t be. I have checked the solution and can not find any margins, paddings, and/or borders. I just started the design process and so below is the only css file im using currently and its only linked to the masterpage.
If anyone has any tips and/or ideas on how to solve this I am all ears because I can’t find the issue, thanks and sorry for the lengthy post.
html, body, form, #wrap {height: 100%;}
form > #wrap {height: auto;
min-height: 100%;}
#main {overflow:auto;
padding-bottom: 150px;}
/* Footer */
#footer {position: relative;
margin-top: -150px;
height: 150px;
clear:both;
background: url(./images/Background.jpg) repeat-x left top;}
#foot p{text-align: center;
font-size: 12px;}
/*Opera Fix*/
body:before {content:”";
height:100%;
float:left;
width:0;
margin-top:-32767px;}
.IE8Fix /*aspx menu fix */
{ z-index: 1000; }
@Tom - Do you have a live version we could look at as it would be easier to debug?
Have you cleared all the default margins and padding from html and body?
@Paul … haha wow thank you. I just started webdesign and I knew I was over complicating the issue, thanks again.
Just tried the new sticky footer for 2010 and it works almost. The footer sticks just slightly below the bottom so a scroll bar appears. You can see most of the footer, but not quite all of it. http://eeredevapps1.nrel.gov/wip/new/
Thanks for creating this. It’s a nifty technique.
@Shauna, recheck your styles. Something in there is interfering with your footer and forcing the scroll bar.
your footer is supposed to be 50px high but somewhere else in there you also call it 24px high, inside programm.css. Also check margins on your paragraphs in the footer. if your content pushes the footer height to be slightly bigger than intended footer dimensions then you get the scroll bar. I often make my footer taller than it needs to be to allow for wiggle room in the content.
Thanks @Stever. I’ve stipped almost all of the styles and almost all of the content to try to get to the issue, but I’m still not seeing it. Here’s the code. You can see it at http://eeredevapps1.nrel.gov/wip/new/
EERE: Weatherization and Intergovernmental Program Home Page
html, body, #wrapper {height: 100%;}
body > #wrapper {height: auto; min-height: 100%;}
#container {overflow:auto;
padding-bottom: 50px;} /* must be same height as the footer */
div#footer {
position: relative;
margin: -50px auto 0 auto; /* negative value of footer height */
height: 50px;
clear:both;
width:1000px;
background-color:#CFF;
}
/*Opera Fix*/
body:before {
content:”";
height:100%;
float:left;
width:0;
margin-top:-32767px;/
}
#wrap {display:table;}
Some content
Some content
@Shauna: Same problem as Tom above:
html,body{margin:0;padding:0}
@Paul O’Brien: Should html,body{margin:0;padding:0}
be in addition to Shauna’s code or in place of certain lines? If in place of, which lines?
Thanks.
@Jon: It’s an addition.
The html and body elements are set to 100%. However browsers apply default margin/padding to html/body so unless you set them to zero you get:
100% + 1 or 2 em padding = bigger than 100%
You also have to take care with the first and last elements on your page because the default margin may collapse on the top or extend through the bottom. Setting a padding top and bottom on inner elements will keep the margin inside the container.
@Paul, thanks for the tip. That did fix my sample code. However, I was actually already including that code in my original. I found the fix was in removing padding from my footer div.
I have the sticky footer completely working, except for one little problem. If the page content is wider than the viewport (making a horizontal scroll bar appear at the bottom of the window) my footer appears on top of (not above) the horizontal scroll bar. In this case, if I try to click the scroll bar rather than the footer, I can’t. I can set the z-index of the footer to -1, so it is behind the scrollbar, but I still can’t scroll low enough on the page to see the footer above the horizontal scroll bar.
Here’s an example image: http://img519.imageshack.us/img519/9680/footerp.png
Any ideas? Thanks for your help.
@Matt - We’d need to see your site structure as the footer shouldn’t be near a horizontal scrollbar and can’t physically be on top of the viewport scrollbar.
Do you have a link?
@Paul-
I more-or-less solved the problem. The scrollbar was actually for the #main div, not the viewport. So, the #main div was overflowing, not the whole page. Removing the #main {overflow: auto;} CSS property fixed this (in FF 3.6.3).
Well, I hoped sincerely it would work!
I need to extensively used absolute positionning in my app and the CSS Sticky footer does not stick.
Can’t Duck tape stick on an absolute surface?
I think I will have to throw JS at my problem, even if I don’t like it.
THANK YOU! I’ve looked for something like this for a long time and really appreciate the code and work you’ve all put into it.
@aadrien,
apparently duct tape does not stick to absolute positioned surfaces. Not sure what the solution to that one might be.
Just an observation… On your sample site, and this site, Reduce the window smaller than your site width, then move the horizontal scroll. Headers, footers, and the main content div no longer fill the width of the window, so if you have background images in there they will not show to the edge of the window.
@stever
I found the solution : use your solution if the page is smaller than the screen, absolute position it using JS otherwise. It works great no matter how big is my page of whatever AJAX it fill in, I just reset the footer position.
I’ve discovered that if the wrap has a fixed width, the IE8 conditional statement results in the page not resizing automatically in IE8. I thought at first that perhaps the problem was linked to something specific to the page I was working on, but I ran a test, and the problem occurs even on simple pages that have nothing more than the wrap, main and footer div’s with a bit of text. I also noticed that the footer does not set all the way at the bottom of the window, there being a gap of 20 or so pixels.
Below are links to three test page. The first one is a fixed width and has the conditional statement. It does not resize automatically in IE8. The second one is a fixed width and does not have the statement. It works fine. The third one has the conditional statement, but does not have a fixed width. It also works fine. In all other ways the three are the same.
http://www.thayersgraphic.com/tests/test-with_statement.html
http://www.thayersgraphic.com/tests/test-no_statement.html
http://www.thayersgraphic.com/tests/test-not_fixed_width.html
Now, I have stared at the code on the page that does not resize automatically until I feel like I’m going blind and see no differences between it and the code taken from this site, other than the added widths and background colors. Am I missing something or is this a real bug?
@ Matthew - I was able to use the sticky footer with YUI Grids
html, body, #doc4 { height: 100%; }
body > #doc4 {height: auto; min-height: 100%;}
#bd {overflow:auto; padding-bottom: 350px; } /* must be same height as the footer - 290 */
#ftContainer {position: relative; margin-top: -350px; /* negative value of footer height */ height: 350px; clear:both; }
/*Opera Fix*/
body:before { content:”"; height:100%; float:left; width:0; margin-top:-32767px;/ }
@Kristofo - and anyone else interested - I was able to use it with html5 by changing the order of the 1st two css lines
html, body, #content-container { height: 100%; }
body > #content-container { height: auto; min-height: 100%;}
#content {overflow:auto; padding-bottom: 450px; } /* must be same height as the footer */
#ft-container {position: relative; margin-top: -450px; /* negative value of footer height */ height: 450px; clear:both; }
/*Opera Fix*/
body:before { content:”"; height:100%; float:left; width:0; margin-top:-32767px;/ }
HTML
I used
to wrap around
and similarly for the footer
wrapped
NOTE: I’ve only previewed the html5 version with firefox on my local computer (just started site development this afternoon) but it seems to work just fine.
cheers! ~Jules
OOPS…
HTML
I used [div id=”content-container”]
to wrap around [section id=”content”]
and similarly for the footer
I wrapped [div id=”ft-container”]
arround [footer]
@MaureenT:
Maureen none of your examples are working properly in IE8. Just grab the bottom of the window and drag downwards and you will see that all are broken.
The problem is that when using display:table you must use height:100% and not min-height:100% and you are over-riding the height:100% with height :auto.
Add height:100%!important to the IE8 rule.
#wrap {display:table;height:100%!important}
If you don’t want to use display:table you can use the “clearfix” technique (http://www.positioniseverything.net/easyclearing.html) on the #wrap instead which also triggers IE8 into behaving.
Yes, I was aware that, when you dragged the bottom of the frame, the footer did not move in any of the examples. I rewrote my post several times, and I now see that I forgot to mention in the final version that I was talking about the footer in test-with_statement.html not moving even when you hit the Maximize button or resized the window with the corner handle, a problem the other two examples don’t have.
I made the change you suggested, and it fixed the problem, for which I thank you, but I need to point out that I was following the instructions as they are at cssstickyfooter.com. If the instructions on that site are wrong, shouldn’t they be corrected?
Below is an exact copy of the text on the page that opens when you click on the “View the Sticky Footer CSS” link. As you can see, the conditional statement does not have height:100%!important, and body > #wrap has the height set at auto.
* {margin:0;padding:0;}
/* must declare 0 margins on everything, also for main layout components use padding, not
vertical margins (top and bottom) to add spacing, else those margins get added to total height and your footer gets pushed down a bit more, creating vertical scroll bars in the browser */
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 {/* thanks to Maleika (Kohoutec)*/
content:”";
height:100%;
float:left;
width:0;
margin-top:-32767px;/* thank you Erik J - negate effect of float*/
}
/* IMPORTANT
You also need to include this conditional style in the of your HTML file
#wrap {display:table;}
*/
@maureenT: Yes that is an error in logic introduced by stever when trying to reduce code and should be amended
The relevant code should be as follows:
html, body{height:100%;}
#wrap {min-height:100%;}
……………….
/* put this within CC for IE6 and IE8 only (not IE7)*/
#wrap{display:table;height:100%}
Thanks Maureen and Paul, I will fix that.
i am working on a mac in a .net environment (with a form surrounding the page), i have made the suggested fixes for this- here is my sample page.
http://www.roxstyle.com/projects/blssi/cms/de-tool-v3/p-add-test-footer.html
i tested for other 100% height divs, etc, but i am seeing a scrollbar in ie7,ie8,FF(pc) and FF(mac). and on both platforms, there is space below the footer in FF.
if anyone could help me, it would be much appreciated.
@roxanne:
Your javascript is inserting a div into the flow below the footer and taking up space.
Its seems to be a ui-datepicker.
You could try setting it’s top position to zero although I don’t know if that will interfere with the elements function.
.ui-helper-hidden-accessible {
top:0;
}
@Paul, a big thanks , i will experiment and let you know.
@Paul Thanks so much, it works, and “Sticky Footer” goes on to more infamy
This article and the comments have been invaluable. Thanks. The sticky footer is fine but I still have a small glitch. My main content container isn’t touching the footer - must be something simple I’ve overlooked.
Also regarding the extra height added to the footer DIV that causes the footer to extend below the fold and make the scroll bar appear on what should otherwise be a short page. I found I needed to compensate for browser defaults that include margin and padding around text elements [ p, h1, h2 etc.]. I increased the negative margin in the footer DIV. Or you can create a style to reset margins and paddings to 0 for all text elements used in the footer.
Please see my example - and suggest a remedy for the too short background DIV. Thanks.
http://www.artandtext.com.au/webTESTsite/stickyFooter-four.html
@Kerry - Yes, resetting all elements to 0 margins and padding is
a mustmandatory for any style sheet.This is the first line of any style sheet I build: * {margin:0;padding:0;}
As for stretching your content area down to touch the footer?? not sure about that one
@Keryy as Steve said the margin on the h4 in the footer is increasing the height and therefore you would need to zero the margins on that element.
h4{margin:0}
Then you can set the negative margin on the footer back to the -50px it should be.
If you want the white content to extend all the way to the bottom then make a white repeating background image that is 800px wide (the width of your content element) and about 10px high. Then just repeat it on the main page wrapper #bgwrap (not the content element itself) at a background-position:50% 0; and it will repeat all the way to the bottom to give the illusion of a full length column.
You cannot have multiple full length columns in css only illusions
thanks for the”definitive”on multiple full length columns.
Love the footer and I thought I had it all set but when I look at the page in IE7 there is a problem. Looking at cssstickyfooter.com on IE7 I notice the same problem with the “tape” footer as well.
Here is one of my pages:http://www.ibayentertainment.com/wheels/r-series/
In IE8 and FF it looks fine but in IE7, scrollbars appear and the stickyfooter sticks to the middle of the page.
Any help would be appreciated.
Thanks,
Jonathan
@Jonathan,a typo/syntax error on my part I believe. I had [if !IE7] when it should have been [if !IE 7] on the conditional style statement. I had an extra space between the if and the ! and no space between the IE and 7. Seems those conditionals are white space dependent.
Thanks Steve! The scrollbar now sticks to the bottom. Any idea why I still have the scrollbars? They show up in IE 7 but not IE 8 or FF.
example:
http://www.ibayentertainment.com/about/
@Jonathan: #page is 1150px wide and has overflow:auto set.
Inside #page there is an element called .pagepost which has 110px padding on each side and contains an image that is 960px wide.
960 + 110 + 110 =1180px which is 30px too big the #page and hence the scrollbars appear.
Reduce the padding on .pagepost by 15px each side or increase the with of #page by 30px.
Wow thank you so much! You guys are the best!
Hi!,
I love this sticky footer, I cant get it to fully work, I keep getting a vertical scrollbar on my #main, any ideas?
Great info! I wrestled with this for a couple of hours before I found your solution. Thanks for sharing.
@John, recheck your IE conditional argument. I had a syntax/typo error thats since been corrected. There needs to be a space between IE and 7 like this [if !IE 7]
Thanks for this its great. I do have a problem though. In all browsers if you manually resize the page a scroll bar appears at the bottom, naturally, but when you then scroll to the right the footer doesn’t follow and leaves a gap where the page was resized - Any ideas how to fix this. If even happens on this very page here.
jHeg, I see what you mean, if you resize the width to less then the content width, then scroll over, that part of footer turns white.
Off hand I dont have an answer to that one. It’s not that the footer is moving, you can see all the other elements in the footer are still where they should be, just the background colors get overwriten to white, except on images.
Until I can find an answer, or someone can suggest one, I would not be too concerned as resizing window width to less than content width would be a very rare behavior for most users, i think.
thanks for the quick reply Stever!!!! I’ll keep looking for a solution. The only reason I found this was because my sister was previewing the site on her laptop and she said the lightbox pictures were not centered and going off the side of the page - not sure if its related - i’ll try to upload tomorrow so you can see. BTW it doesnt happen on my laptop so will test on different computers too tomorrow.
@jheg: That has nothing to do with the sticky footer as such and will occur on most sites.
It is simply the fact that the footer is 100% wide and when the viewport is closed smaller say to 600px wide then the background only extends to 600px.
If you then scroll outside this area there will be no background because the viewport is is only 600px wide and 100% = 600px still.
The solution is to set a min-width on the footer to the same width as the element that causes the scroll. In stevers case this would be 820px as follows:
#footer {
background: #444444 url(’images/footer.gif’) repeat-x;
color:#ffffff;
font-size:11px;
font-family:Verdana, Arial, sans-serif;
min-width:820px
}
Now the background will be intact
Yeeee Haaaaa!!! Genius thanks Paul!
The CSS mastery that is Mr. O’brien delivers yet again!
In our project we needed two nested wrapper divs in order to have one background image behind another background image. This was because we had a primary background image (gray striped) repeating on the x and a secondary background image (transparent drop shadow border) repeating on the y. There seemed to be no solution to this problem without causing scrolling, gap or overlap issues. We decided to use plain div borders in place of the secondary background image, though it still required the use of two nested wrapper divs. In the end, we used the sticky footer code and added an outer wrap around the whole thing. Then we moved the bottom padding from the main div to the outer wrap and turned off the negative top margin on the footer div. Then we used a bit of jQuery to reduce the extra height on the outer wrap caused by the padding. Everything seems to be working perfectly now. Thanks for the stick footer code!
Here is the jQuery:
$(document).ready(function() {
var divHite = $(’#outerwrap’).height();
$(’#outerwrap’).height(divHite-210);
});
Here is the css:
#outerwrap {
margin:auto;
width:800px;
background-color:#ffffff;
height: 100%; /*added for sticky-footer */
border-left:2px solid #656565;
border-right:2px solid #656565;
padding-bottom:210px; /*added for sticky-footer */
}
#wrap { /*added for sticky-footer */
float:left;
width:796px;
min-height: 100%; /*added for sticky-footer */
}
#header {
float:left;
width:100%;
position:relative;
}
#main {
float:left;
width:100%;
position:relative;
overflow:auto; /*added for sticky-footer */
/*padding-bottom: 210px; /*added for sticky-footer */
}
#footer {
float:left;
width:796px;
height:210px;
position: relative; /*added for sticky-footer */
/*margin-top: -210px; /*added for sticky-footer */
clear:both; /*added for sticky-footer */
background-color:#ffffff;
}
Thankyou for this code. It now works great but I did have problems getting it to work accross all browsers.
Basically because of the multilayered nature of the site I needed to include:
#wrap {display:table;}
to CSS as full screen in Mozilla, Opera and Chrome the footer was appearing at the end of the content div NOT the bottom of the window.
Not sure if this is an IIS/ASP.net windows thing
@raz, in .net platforms your pages probably reside inside a form tag. I think you need to add the form tag to the height:100% statement like this;
html, body, form {height: 100%;}
Finally something that worked on my website
I used top and bottom margins, but it still worked, thank you!
Thank you so so much for this solution.
just want to note, that body { display: table; } can break the stricky footer, but its still a perfect solution!! thx so much
just wanted to step by and say ‘thank you’
I made a drupal website and your solution works perfectly on all tested browsers (opera, chrome, ie7/ie8, safari, firefox)
thanks!
Hi, thanks for this code, works great.
However I ran into one problem with Opera (version 10.63). The overflow:auto for the #main div makes background images (within other div’s of the #main section) disappear. This is probably a weird bug in Opera, but maybe this knowledge will be of use.
I removed the overflow:auto altogether and it still works in FF, Saf, Chrome and Opera.
So I was wondering why overflow:auto is needed. For IE or older versions of the standard browser?
Cheers,
Maggy
Hi Maggy, the overflow is in place to clear the floats in that section. If you don’t have any floats then the overflow could be removed.
I’ve checked Opera 10.63 and there seems to be no issues in that section so it is probably something else in your code that is the problem.
You could always clear floats with the “clearix method” but I don’t see a need.
If you have an example of where the images are missing I’ll take a look. Older Opera quite often hides things where position:relative is used and also likes it added to the children but the newer versions seem ok.
Hi Paul,
Thanks for the explanation. Before implenting your css for the sticky footer I had put a clearfix div, that’s why everything still was ok. I didn’t know that you could clear floats with overflow:auto, thanks!
It could be something else of course, but it worked fine, untill I added the overflow:auto and when I removed that, it worked again..
The html (I am still working on it, so far from finished ;-)) is here:
http://dev.operatiecreatie.nl/projects/pedro/index.html
It’s the polaroid frame background with the image on top. The image was still shown only the polaroid background was hidden.
Thanks for your time!
Cheers, Maggy
Hi Maggy,
I had a quick look at the page and the bug seems to be caused in conjunction with the transform filter. It seems to be a bit buggy in Opera and the overflow rule does seem to be affecting it.
This is nothing to do with the sticky footer routine as such and seems to be a problem with the transform itself.
You can clear the floats instead using the clearfix method instead of the overflow method and that seems to work ok. However, I notice you have corrupted the clearfix routine and are also using it incorrectly.
The clearfix is applied to a the parent wrapper of the floats and not as a stand alone div (which would defeat the whole purpose of its invention :)).
Just add a clearfix class to #wrapper.
… div id=”wrapper” class=”grid_12 clearfix”
In the clearfix rules you have missed out the content property which is the method needed for clearing the floats.
.clearfix:after {
clear:both;
display:block;
height:0;
visibility:hidden;
content:” “;
}
Hope that makes sense.;)
Hi Paul,
Wow thanks! That really makes sence. It seems I have learned clearfix the wrong way from the beginning, while it does the job most of the times I have had trouble which I didn’t understand.
Thanks a lot for pointing this out to me!
Cheers,
Maggy
This is great. The first sticky footer I’ve found that works.
It solved all my problems with the footer appearing at the top of the page (overlapped by the content).
Loads of kudos to you!