Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The footer as it stands right now is always just under the content. If the content is not long enough, it won't be at the bottom of the page. I had this same problem in a theme I build, and this is how I solved it with js. This just degrades to the current functionality. Obviously you need to change this to match your divs.
$(document).ready(function() {
var footer_height = $('#footer').height();
var footer_pos = $('#footer').position();
var window_height = $(window).height();
var page_height = $('#page').height();
var page_pos = $('#page').position();
var page_total = page_pos.top + page_height;
var footer_new_pos = window_height - footer_height - page_total;
var test = footer_height + page_total;
if (test <= window_height) {
if (footer_pos.top < window_height) {
$('#footer').css('position', 'relative');
$('#footer').css('margin-top', footer_new_pos);
}
}
});
Hope this proves useful!
Comments
Comment #1
stephthegeek CreditAttribution: stephthegeek commentedTagging for implementation when Skinr supports page styles
Comment #2
willvincent CreditAttribution: willvincent commentedWouldn't this be better implemented with css than javascript?
As demoed here: http://www.cssstickyfooter.com/
Comment #3
stephthegeek CreditAttribution: stephthegeek commentedIf we had a fixed width footer, yes :) afaik there is still no way to do a sticky footer when its of an unknown height.
Comment #4
codycraven CreditAttribution: codycraven commentedTo me, JavaScript should be left out of contributed themes output. I think this would be of much better use as a separate contributed module. In the module there would be a configuration that would allow specifying the id of the block element that should be attached to the bottom of the page.
A great reason of why this should be a contributed module, and definitely doesn't belong in a theme, is that you may have bugs. For example in your JavaScript you do not take in to account the content resizing. This means that if JavaScript modifies the content of the page once rendered your footer will not adjust. Best case scenario your css is not applied to footer and you end up with a page where the footer is not "attached" to the bottom if the content is resized smaller. Worst case your page starts very small applying a lot of margin to the top of your footer and your footer becomes lost at the bottom of a scroll with blank space above it when content resizes.
Based on my thoughts on this I believe this issue should be closed.
Comment #5
stephthegeek CreditAttribution: stephthegeek commentedIf we were to implement this, it would be an optional setting. It's a desirable feature for many people but is not appropriate for all cases as you have pointed out.
Haven't had a chance to review in detail yet though, probably not until after Fusion 1.0.
Comment #6
codycraven CreditAttribution: codycraven commentedI know this is somewhat dragging the issue out, even though it may be a non-issue but...
Another issue with using the supplied JS is that if the sub-theme of Fusion is using a background and/or border on Main and/or Postscript Bottom then the margin-top will result in a blank gap above the footer. It should instead be applied to the block element prior to Footer-Wrapper and then down the correct number of layers so as the continue the background down to the footer. This gets even worse if the Footer region is not rendered and instead is only the footer-message-wrapper...
Also, @stephthegeek you are right about this being a desirable feature for many cases. For this reason there should be a separate module contributed so that this can be applied to many different themes and not just Fusion based.
Comment #7
stephthegeek CreditAttribution: stephthegeek commentedThis will get a lot easier in D7 with region-based Skinr styles :)
Comment #8
lolmaus CreditAttribution: lolmaus commentedIt's pretty easy to make footer stick in D6 in your Fusion subtheme, providing that you know and declare footer's height.
First of all, copy page.tpl.php from Fusion core to your subtheme. Open it and drag footer output outside the <div id="page"> like this:
After that, add the following CSS to your CSS file:
Don't forget to replace "FOOTER-HEIGHT" with same number three times (one being negative).
Voila!
This is #2 solution adapted for Fusion.
This solution won't let you apply a stick-to-bottom backround to and .
PS And here's a fix for Adminisration menu always on top:
Comment #9
bigpepper CreditAttribution: bigpepper commentedI used this tutorial: Sticky Footer
Worked super for me
Comment #10
lolmaus CreditAttribution: lolmaus commentedHey bigpepper, this is the same solution as above. It works only for fixed-height footer. :(
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedI've searched for a sticky footer for D7 version of Acquia Marina, but I couldn't find anything.
Will the CSS/JS examples work for D7? My site is running drupal-7.10, fusion-7.x-1.x-dev and acquia_marina-7.x-1.x-dev.
Comment #12
elianarunner CreditAttribution: elianarunner commentedAnyone solved this issue for D7 fusion starter? Drupal 7.22, Fusion7.2 beta.
Comment #13
elianarunner CreditAttribution: elianarunner commentedThak you Lolmaus, your solution works also on drupal 7 !
There is only one line for the div of footer in page.tlp.php and it should be outside the page.
the css applies the same. Hope this helps d7 Users.
Comment #14
Poieo CreditAttribution: Poieo commentedThis would definitely have to be a user configurable option to turn off and on for the header and/or footer.
I would be glad to accept any working patches against the 7.x-2.x branch.
Comment #15
Poieo CreditAttribution: Poieo commentedThis will be considered for the 7.x-3.x version.