4

I need to put a sticky footer on my pages , however i don't have a definite height set for my footer . On smaller screens - the rows resize and footer becomes longer .

Therefore , the default sticky footer example provided on getbootstrap does not work since it requires a fixed footer height.

Any way to implement this ?

/* Sticky footer styles
-------------------------------------------------- */
html {
  position: relative;
  min-height: 100%;
}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  line-height: 60px; /* Vertically center the text there */
  background-color: #f5f5f5;
}


/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */

body > .container {
  padding: 60px 15px 0;
}

.footer > .container {
  padding-right: 15px;
  padding-left: 15px;
}

code {
  font-size: 80%;
}
Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
Sam.tuver
  • 679
  • 2
  • 9
  • 19
  • Possible duplicate of [How to make a fluid sticky footer](https://stackoverflow.com/questions/16901707/how-to-make-a-fluid-sticky-footer) – Tieson T. Aug 28 '17 at 05:38
  • Not a duplicate, that is really old question, and this question is specific to bootstrap 4. – Adarsha May 14 '20 at 21:18

3 Answers3

23

Now that Bootstrap 4 is flexbox, a sticky footer can be done using...

<wrapper class="d-flex flex-column">
    <nav>
    </nav>
    <main class="flex-fill">
    </main>
    <footer>
    </footer>
</wrapper>

body, wrapper {
   min-height:100vh;
}

.flex-fill {
   flex:1 1 auto;
}

Demo: Bootstrap 4.0 Sticky Footer

Note: The flex-fill utility class is included in the Bootstrap 4.1 and later release. So after that release the extra CSS for flex-fill won't be needed.

As of Bootstrap 4.1, there is a min-vh-100 utility class which means you don't need the extra CSS.

Demo: Bootstrap 4.1+ Sticky Footer

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
6

A very simple way is using a navbar as a footer. It comes with a fixed-bottom class that is really handy. To change your spacing you can see the documentation here... https://getbootstrap.com/docs/4.2/utilities/spacing/

<nav class="navbar fixed-bottom navbar-light bg-light">
  <a class="navbar-brand" href="#">Fixed bottom</a>
</nav>
cupidsTrick
  • 61
  • 1
  • 4
0

Use min-height instead of height to make it variable height.

https://codepen.io/hunzaboy/pen/prxgRb

Also on smaller screens just remove the absolute position and make it static.

Aslam
  • 9,204
  • 4
  • 35
  • 51