Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force my footer to stick to the bottom of any page in CSS?

This is my code:

#footer {    font-size: 10px;    position:absolute;    bottom:0;    background:#ffffff; } 

I've no idea what is wrong with this - can anyone help?

EDIT: For some more clarity on what's wrong: The footer is displayed on the bottom as expected when the page loads. However, when the web page's height is > than the dimensions on the screen such that a scroll bar appears, the footer stays in that same location. That is to say, when the height of the page is <= 100%, the footer is at the bottom. However, when the page height is >100%, the footer is NOT at the bottom of that page, but at the bottom of the visible screen instead.

EDIT: Surprisingly, none of the solutions below worked. I ended up implementing a sidebar instead.

like image 567
oxo Avatar asked Apr 01 '11 17:04

oxo


People also ask

How do I get my footer to stay at the bottom CSS?

Keep the footer at the bottom by using Flexbox Make sure that you are wrapping everything in a <div> or any other block-level element with the following CSS styles: min-height:100vh; display:flex; flex-direction:column; justify-content:space-between; .


2 Answers

You're probably looking for this example:

<div class="wrapper">     Your content here     <div class="push"></div> </div> <div class="footer">     Your footer here </div> 

CSS:

For a 142-pixel footer

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/  */ 
like image 168
SLaks Avatar answered Sep 20 '22 12:09

SLaks


Try this:

position: fixed;   bottom: 0; 
like image 29
jeegnesh Avatar answered Sep 18 '22 12:09

jeegnesh