Search code examples
htmlcsssticky-footer

How do I get a sticky footer?


I know there have been plenty of questions regarding sticky footers, but I can't seem to get them to work on my page.

Can anyone help me make my footer sticky, not fixed?

My HTML

<div id="container">
      <div id="header"></div>
      <div id="content"></div>
      <div id="footer"></div>
</div>

My CSS

#container {
    width: 980px;
    min-height: 100%;
    margin-left: auto;
    margin-right: auto; }

#content {
    width: 100%;
    min-height: 100%;
    margin: 40px 0;  }

#footer {
    width: 3000px;
    min-height: 185px;
    background-color: rgb(0,173,239);
    margin-left: -1000px;  }

I have tried various positions (relative, fixed etc) but it doesn't work. I seem to get my footer fixed and covering content. Any suggestions?


Solution

  • Try this CSS:

    body {
        min-height: 100%; }
    
    #container {
        width: 980px;
        min-height: 100%;
        margin-left: auto;
        margin-right: auto; }
    
    #content {
        width: 100%;
        min-height: 100%;
        margin: 40px 0;
        margin-bottom: 290px;  }
    
    #footer {
        width: 100%;
        min-height: 185px;
        background-color: rgb(0,173,239);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;  }