This question already has an answer here:
I am trying to have my footer (just a div with a line of text in it) be at the bottom of the screen if the content doesn't go all the way to the bottom, or be at the bottom of the content if the content requires scroll bars. If the content doesn't require scroll bars, it works perfectly, but when the content is too long, the footer is still in the same spot, sitting right on top of the content.
My basic div structure is:
<div id="container">
<div id="body"></div>
<div id="footer"></div>
</div>
My corresponding CSS (stripped down somewhat):
body {
margin: 0;
padding: 0;
height: 100%;
}
html {
margin: 0;
padding: 0;
height: 100%;
}
#container {
width: 674px;
min-height: 100%;
height: 100%;
position: relative;
margin: 0 auto;
}
#body {
width: 616px;
padding: 5px 14px 5px 14px;
margin: 0 auto;
padding-bottom: 20px;
}
#footer {
position: absolute;
bottom: 0;
width: 644px;
height: 20px;
margin: 0 auto;
}
the easiest hack is to set a
min-height
to your page container at 400px assuming your footer come at the end. you dont even have to put css for the footer or just awidth:100%
assuming your footer is direct child of your<body>
The simplest solution is to use
min-height
on the<html>
tag and position the<footer>
withposition:absolute;
Demo: jsfiddle and SO snippet:
I would like to share how I solved mine using Javascript function that is called on page load. This solution positions the footer at the bottom of the screen when the height of the page content is less than the height of the screen.
Hope that helps.
Why not using:
{ position: fixed; bottom: 0 }
?do it using jQuery put inside code on the
<head></head>
tagUse min-height as some pixel value, instead of %. Like: min-height:620px; height:auto;
and footer as: