I'm currently trying to save the footer below using Javascript. This is the result:
document.getElementsByTagName('body').onload = function() {KeepFoot()}; var element = document.getElementById('container'); var height = element.offsetHeight; function KeepFoot() { if (height < screen.height) { document.getElementById("footer").style.position = "fixed"; document.getElementById("footer").style.bottom = "0"; document.getElementById("footer").style.left = "0"; document.getElementById("footer").style.right = "0"; } }
My idea was to take the height of the div container and compare it with the PC resolution height. If the height of the div container is less than the height of the PC resolution, set the footer position: fixed;
But the problem in the script arises because it does not work.
Another question the script I created would be good for the footer to be below?
HTML:
<html> <head> ... </head> <body> <div id="container"> <div id="header"></div> <div id="content"></div> <div id="footer"></div> </div> </body> </html>
javascript sticky-footer
Keaire
source share