I am creating a page with a position: fixed;
footer, which will need to expand on scroll, but take at least 100% of the page. I wanted to make my main wrapper take the whole space without ever being behind the footer. So created a min-height
with calc(100vh - 120px)
. Here is the code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body,
html,
#app {
min-height: 100vh;
max-width: 100vw;
}
#wrapper {
min-height: calc( 100vh - 120px);
height: auto;
max-width: 100vw;
}
footer {
height: 120px;
width: 100%;
}
<footer>
<section id="lien-express">
<div class="lien-express-1">
<p>Lien lien-express</p>
</div>
<div class="lien-express-2">
<p>Lien lien-express</p>
</div>
</section>
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/about">About</RouterLink>
<RouterLink to="/portfolio">About</RouterLink>
<RouterLink to="/catalogue">About</RouterLink>
</nav>
</footer>
<main id="wrapper">
<RouterView />
</main>
My problem is that when I tell the <div>
to be more than 100vh
the calc
function is not working. The <div>
is taking all the space without talking the calc
into account:
Here is the screenshot of the console to show you the difference
With 100vh
:
With more than 100vh
:
2
Answers
So the final solution that worked for me was :
The calc don't take under account an auto height. So when i was trying to calculate with calc i could not calculate with an unknown variable. But i could create a parent that was doing the job of the calc by applying a padding, at put the element inside it.
If what you really want is a layout that will always fill at least 100% of the viewport and the main content stretches to fill whatever space is available while the footer is at the bottom of the content, then you should use grid like so:
Edited so the footer always sticks at the bottom of the viewport