|| #resource #css

BulmaCSS: Sticky Footer

Stick the footer to the bottom of the page in BulmaCSS 🎨

Problem

When building a website I often want to make sure the footer sticks to the bottom of the page. Even when there isn't enough content to fill the entire page.

Diagram showing the page footer being moved downwards

Solution

The following example shows how to setup your HTML and CSS so that the footer sticks to the bottom of the page if the page content is short.

HTML

<div class="wrapper-root">
  <div class="wrapper-content">...</div>
  <footer class="footer">...</footer>
</div>

CSS

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

.wrapper-content {
  flex: 1;
}

There are a few things going on:

  1. Set the min-height of the page to the view-height (browser window height)
  2. Split the page into 2 sections:
    1. Content
    2. Footer
  3. Set the content section to auto-expand (flex: 1)

Details

I love Bulma CSS. However, the main issue I come across when using it is the footer showing half-way up the page when the page is mostly empty. The solution above fixes that issue.

This approach ensures the footer is always show either a) at the bottom of the content (if the content extends beyond the screen), or b) at the bottom of the screen (if the content is smaller than the screen).

The footer will not always be fixed at the bottom of the browser window.

This code should work for any HTML and CSS code you write, however, I have only used it with Bulma.


Note

When I first implemented this, the page was not rendering correctly. I found the problem was how I was defining the .container class. My code looked like:

<div class="wrapper-root">
    <div class="wrapper-content container">
        ...
    </div>
    <footer class="footer"></footer>
</div>

But it should have been:

<div class="wrapper-root">
  <div class="wrapper-content">
    <div class="container">...</div>
  </div>
  <footer class="footer"></footer>
</div>

Make sure you don't apply the custom .wrapper-content style and Bulma's .container style to the same div element.


Maybe try another one?

Conventional Commits What "conventional commits" are and how I use them
2023.12.03
Reset Git Commit Author How to reset the author of one (or more) git commits
2022.09.05
The random places things come from Story behind my website's new colour palette
2024.08.08