The most annoying bit I run into whenever I make a web-page from scratch is getting the footer to stay at the bottom properly. The web is plagued with pages where the footer sits awkwardly in the middle on high definition screens.
Popular questions that talk about this:
My issue with the (valid) answers given to those questions is that they're relying on knowing beforehand the size of your footer, something that makes the website less responsive.
Is there any way to have the footer fixed at the bottom of the page that works on any screen and doesn't rely on predefined constants?
In the app I'm working on, I made use of @media
to separate how it looks on mobile and desktop but discovered that 100vh
is not always the full view port on mobile (discussion here). After some fiddling, I got this to work (as far as my Google Chrome developer console is concerned).
(Header and Footer are react components)
<Header/>
<div className="content">
<p>Content</p>
<div>
<Footer/>
.content {
@media screen and (max-width: 738px) {
min-height: calc(100vh - #{$footer-height-mobile} - 1.92 * #{$navbar-height});
}
@media screen and (min-width: 738px) {
min-height: calc(100vh - #{$footer-height-desktop} - #{$navbar-height});
}
}
The 1.92
was the only value that gave me the expected behaviour. Any less and it overflows, any more and it leaves empty space at the bottom. Is this an actual solution, or is it just a thing that happened to work in Google Chrome?