Updated Answer
The initial answer is over five years old, and it fails that the padding is not updated if the footer increases or decreases. You can bind to the window resize event and call it with every fire, but it will be a bit overwhelming.
Instead, I recommend that you bind to the window.onresize event, but throttle the logic so that we donβt calculate styles, break the DOM, or call layouts dozens of times per second :
(function () { "use strict"; var body = document.querySelector( "body" ); var footer = document.querySelector( "footer" ); window.addEventListener(
When the page loads, we immediately launch the adjustContainerPadding method. This method sets the paddingBottom body according to the calculated footer height. Note that the window.getComputedStyle method requires IE9 or more.
Fiddle: http://jsfiddle.net/jonathansampson/7b0neb6p/
Original answer
I would recommend that you (for simplicity) just use the cssstickyfooter code and set the css values ββvia javascript (the following jQuery code).
$(function(){ var footerHeight = $("#footer").height(); $("#main").css("padding-bottom", footerHeight); $("#footer").css("margin-top", -footerHeight); });
code not verified but should work just fine
No matter how much content you have in the footer, this will automatically reset the CSS values ββfor you.
Sampson
source share