10

I'm trying to use this sticky footer:

http://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/

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

.content{
  flex: 1;
}

But it messes up the rendering at the < 768px widths.

Any simple css fix to get it work for all resolutions?

http://jsfiddle.net/2xvv5mod/

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
tachyonflux
  • 20,103
  • 7
  • 48
  • 67

4 Answers4

13

Bootstrap 4 now uses flexbox by default so it's easier to get a sticky (not fixed) footer w/o additional CSS for the flexbox. You just need to ensure the body has min-height...

body {
  min-height: 100vh; 
}

Then use the flexbox utility classes...

<body class="d-flex flex-column">
  <nav></nav>
  <main class="flex-grow"></main>
  </footer></footer>
</body>

Bootstrap 4 Flexbox Sticky Footer

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
  • @ottz0 has the more bootstrap 4 way of achieving this. – Jogai Oct 26 '20 at 13:01
  • @Jogai. Thanks and there are also specifically [tag:bootstrap-4] questions on this https://stackoverflow.com/questions/45912296/bootstrap-4-sticky-footer-dynamic-footer-height/45919356#45919356 and https://stackoverflow.com/questions/46722697/bootstrap-4-sticky-footer-not-sticking/49562840#49562840 – Carol Skelly Oct 26 '20 at 13:24
6

You need to give the flexbox item a width of 100%.

In this case, that would be that .content element:

Updated Example

body {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}
.content {
    flex: 1;
}
@media only screen and (max-width: 768px) {
    .content {
        width: 100%;
    }
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
3

Adding vertical height worked for me

<body class="d-flex flex-column min-vh-100">
    <nav>this is text</nav>
    <main class="flex-grow-1">this is text</main>
    </footer>this is text</footer>
</body>
ottz0
  • 2,595
  • 7
  • 25
  • 45
0

I'd suggest to take out a bit of confusion since the snippet does not really match with the linked details. Plus it has a typo. Just to let the framing tags work as fix points.

<body class="d-flex flex-column">
  <nav></nav>
  <section class="container-fluid flex-grow-1"></section>
  <footer></footer>
</body>
woodz
  • 737
  • 6
  • 13