How to stick footer to bottom (not fixed) even with scrolling

I think this might help you.

Just showing you the way how to achieve what you want.

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
#wrapper {
  min-height: 100%;
  position: relative;
}
#header {
  background: #ededed;
  padding: 10px;
}
#content {
  padding-bottom: 100px;
  /* Height of the footer element */
}
#footer {
  background: #ffab62;
  width: 100%;
  height: 100px;
  position: absolute;
  bottom: 0;
  left: 0;
}
<div id="wrapper">

  <div id="header">
  </div>
  <!-- #header -->

  <div id="content">
  </div>
  <!-- #content -->

  <div id="footer">
  </div>
  <!-- #footer -->

</div>
<!-- #wrapper -->

Make sure the value for 'padding-bottom' on #content is equal to or greater than the height of #footer.

Update:

JSFiddle Demo to play around.


I'm using Bootstrap 4 and this worked for me link.

I did this way in the CSS file (base.css):

html {
    height: 100%;
}

body {
    min-height: 100%;

    display: flex;
    flex-direction: column;
}

footer{
    padding: 3em;
    margin-top: auto;
}

And I've linked the css file in the html (base.html):

<head>
    <link rel="stylesheet" type="text/css" href="'<path to css>'"/>
</head>

The accepted answer might be a bit outdated since we have Flexbox now. Give the container a min-height: 100vh and the footer a margin-top: auto so you don't have to deal with absolute positioning and fixed heights.

body {
    margin: 0;
}

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    background-color: #FFCCCC;
}

.content {
    background-color: #CCFFCC;
}

.footer {
    background-color: #CCCCFF;
    margin-top: auto;
}
<div class="container">
    <div class="header">header</div>
    <div class="content">content</div>
    <div class="footer">footer</div>
</div>

Tags:

Html

Css