Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stick a footer to bottom in css?

I am having the classic problem for the positioning of a Footer on the bottom of the browser. I've tried methods including http://ryanfait.com/resources/footer-stick-to-bottom-of-page/ but to no good result: my footer always keeps appearing in the middle of the browser window in both FF and IE.

In the HTML i got this simple structure

<form>  ...  <div class=Main />  <div id=Footer /> </form> 

Here is the css code that is relevant for the css footer problem:

    *     {         margin: 0;     }   html, body {     height: 100%; }       #Footer     {         background-color: #004669;         font-family: Tahoma, Arial;         font-size: 0.7em;         color: White;         position: relative;         height: 4em;     }        .Main     {         position:relative;         min-height:100%;         height:auto !important;         height:100%;          /*top: 50px;*/          margin: 0 25% -4em 25%;          font-family: Verdana, Arial, Tahoma, Times New Roman;         font-size: 0.8em;         word-spacing: 1px;         line-height: 170%;         /*padding-bottom: 40px;*/     } 

Where am I doing wrong? I really have tried everything. If I missed any useful info please let me know.

Thank you for any suggestion in advance.

Regards,


thank you all for your answers. it worked with:

position:absolute;     width:100%;     bottom:0px; 

setting position:fixed did not work in IE for some reason(Still showed footer in the middle of the browser), only worked for FF.

like image 994
Amc_rtty Avatar asked Sep 28 '09 18:09

Amc_rtty


People also ask

How do I make my footer stick in CSS?

Method 2: (fixed height footer) Apply display:flex and flex-direction:column to the body . Apply margin-top:auto the footer . You're done, because auto margins inside flex containers absorb all available free space, making the footer stick to the bottom.

How do you make things stick to the bottom in CSS?

Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.

How do I stick footer to the bottom when page content is less?

Quick answer: Add “display:flex; flex-direction:column; min-height:100vh;” to body or appropriate layout body element, then add “flex:1;” to content wrapper element/section. I will explain few ways to keep or stick the footer to the bottom of the page if there is not enough content.


2 Answers

Try setting the styles of your footer to position:absolute; and bottom:0;.

like image 138
Nick Larsen Avatar answered Oct 06 '22 00:10

Nick Larsen


#Footer {   position:fixed;   bottom:0; } 

That will make the footer stay at the bottom of the browser window no matter where you scroll.

like image 39
codedude Avatar answered Oct 06 '22 00:10

codedude