Search code examples
cssfootersticky-footer

How to stick footer to bottom? With a little twist


So basicly i want to stick footer on the bottom of my page

But the content of my page is dynamic, so in some cases the content is long, in some cases it is short

I've searched through google and found many results, but when i try it, they work when the content is short, but if the content is long it will stick on the bottom of the window (not page) and overlap the content

It's not matter if it uses javascript, but if you have the pure CSS ones it will be better


Solution

  • This doesn't use a fixed position so it won't always show up at the bottom of your viewport.

    CSS from here

    You can also see a discussion about this here

    * {
        margin: 0;
    }
    html, body {
        height: 100%;
    }
    .wrapper {
        min-height: 100%;
        height: auto !important;
        height: 100%;
        margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
    }
    .footer, .push {
        height: 142px; /* .push must be the same height as .footer */
    }
    
    /*
    
    Sticky Footer by Ryan Fait
    http://ryanfait.com/
    
    */