0

I want my footer to be always on the bottom of the page, even when the content is very short. I have checked this one http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page but does not work.

My HTML:

<body>
   <div id="container">
      <div id="header"></div>
      <div id="content"></div>
  </div>
  <div id="wrap-footer">
      <div id="footer"></div>
  </div>
 </body>

My CSS:

 #footer { 
   height: 320px;
   position: absolute;
   width: 100%;
   bottom: 0;
 }

With this one, when I have a short content is ok, but when I have a long one the footer goes in the middle of the page and stuck there. Does anyone have an idea ? Thanks in advance

novellino
  • 1,069
  • 4
  • 22
  • 51
  • `position: fixed` is the correct answer, but be aware that browser support for this is far from universal. In the past I've had to use something javascript-based to keep my footer in the right place. See http://www.quirksmode.org/css/css2/mobile.html for more details on browser support. – Dan Oct 18 '13 at 14:43
  • position fixed, make the footer stick on the end on the page, but not where the content ends. so is not what I want – novellino Oct 18 '13 at 14:44
  • @Dan From my understanding, he wants it at the bottom of the document, not the browser. – ediblecode Oct 18 '13 at 14:45
  • Just realised that's what I get for skimming through a question - my apologies.. – MackieeE Oct 18 '13 at 14:45
  • @jumpingcode How is that different from what happens if you don't have a `position` at all and let the browser layout divs as normal? – Dan Oct 18 '13 at 14:49
  • @novellino I think I've the solution – ediblecode Oct 18 '13 at 14:50
  • 1
    This question has been asked before. A lot. The simplest solution that I always end up using can be found here: http://ryanfait.com/sticky-footer/. Bear in mind, this is pretty much impossible without fixing the height of your footer (until `position: sticky` is a reality). – CherryFlavourPez Oct 18 '13 at 15:00
  • There are thousands of tutorials on the web that show exactly this. – Sliq Oct 19 '13 at 20:46
  • I used this one http://www.cssstickyfooter.com/ at the end and it worked. – novellino Oct 21 '13 at 14:17

5 Answers5

0

If you add position:fixed; to your footer it should work

#footer { 
   height: 320px;
   position: fixed;
   width: 100%;
   bottom: 0;
 }
SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
0

Try using position:fixed instead.

http://jsfiddle.net/akMpT/

If you're just looking to push the footer down to the bottom of the page (as jumpingcode suggests), without fixing its position. Set the container height to 100%, and also any parent elements including <html> and <body>

Fiddle for the height:100% method: http://jsfiddle.net/akMpT/1/

As pointed out in the comments my second method isn't perfect. This subject has been tackled a hundred times, here's one example of how to do it correctly with CSS. Google has countless others. http://css-tricks.com/snippets/css/sticky-footer/

logic-unit
  • 4,195
  • 12
  • 47
  • 72
0

In this case it's because you are applying the positioning to the wrong element.

JSFiddle Demo

#wrap-footer { 
   height: 320px;
   position: absolute;
   width: 100%;
   bottom: 0;
    background:red;
 }
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

providing "position:fixed" will keep your footer on the bottom or anywhere you like to keep it with additional properties (top:0;bottom:0;,left:0;,right:0;). Use them with "position property".

 #wrap-footer
{
   position: fixed;
   left:0;
   bottom: 0;
   height:10px; /*according to your will*/
}
0

Sticky Footer (Bottom of Browser)

DEMO FIDDLE

CSS

footer { position:fixed; bottom:0px; }$(document).ready(function() {

Normal Footer (Bottom of Document)

DEMO FIDDLE

CSS

footer { bottom:0px; }

jQuery

$(document).ready(function() {
    moveFooter();
    $(window).resize(function() {
        moveFooter();
    });

    function moveFooter() {
        var dH = $(document).height();
        var wH = $(window).height();

        if (dH < wH)
            $('footer').css("position", "relative");
        else
            $('footer').css("position", "absolute");
    }
});
ediblecode
  • 11,701
  • 19
  • 68
  • 116