Bootstrap 4 - Sticky footer - Dynamic footer height

前端 未结 3 536
清酒与你
清酒与你 2020-11-27 08:14

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 .

相关标签:
3条回答
  • 2020-11-27 08:24

    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

    0 讨论(0)
  • 2020-11-27 08:37

    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>
    
    0 讨论(0)
  • 2020-11-27 08:51

    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.

    0 讨论(0)
提交回复
热议问题