0

I am calculating the window height and other elements height and making the footer stay at bottom. I tried with JavaScript but the footer is only taking the header element height and aligning the footer just below the header. I wanted to make the footer stay at bottom with the help of JavaScript. Using position as fixed in css clips the content. I want the footer to grow as and when the content grows. Thats the reason i am trying to achieve this in JavaScript or JQuery and not pure CSS.

JSFiddle Code

$(document).ready(function() {
function pageheight() {
debugger
  var ContainerMinHeight = ($(window).height()) - (($("header").height()) + ($("footer").height() + 27));
  $("body").css("min-height", ContainerMinHeight);
}
pageheight();;
});
tkamath99
  • 629
  • 1
  • 12
  • 32

6 Answers6

0

Use fixed positioning, don't really need to use jquery at all

Jakub L
  • 17
  • 2
0

you can do it by css:

position: fixed

Reference here: https://www.w3schools.com/css/css_positioning.asp

odarino
  • 62
  • 4
0

Try with css

position: fixed

Apply this css at the parent div

jyotishman saikia
  • 2,079
  • 1
  • 15
  • 11
-1

You can do with CSS only. No need to use Js or Jquery.

Reference: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_fixed_footer

Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43
-1

You can try to use CSS with position fixed. Example CSS rules: enter image description here

Artur R.
  • 248
  • 2
  • 9
-1

You can use fixed position in css. You also have to take care that the html and the body element take 100% of the windows height.

Tarik Weiss
  • 336
  • 2
  • 15