So this is my layout:
<div style="display: flex; min-height:100vh">
<div>Sidebar</div>
<div style="flex-grow: 2">All my views</div> // Container of the main content of my app
</div>
The result is this:
The sidebar is stuck to the left and the main content is taking most of the space, perfect.
Inside the container of my app, let's say I wan't a login component:
<div style="display: flex; min-height:100vh">
<div>Sidebar</div>
<div style="flex-grow: 2">
<div style="display: flex; justify-content: center; align-items: center; height:100%">
My login component
</div>
</div>
</div>
I center it with Flexbox and by setting a height: 100%
. Since the parent container is itself stretching the height fixed by its parent, it works.
Now the problem:
In mobile, the sidebar is on the top of the page. Therefore, I'm adding to the root container a flex-direction: column
to it, like that:
<div style="display: flex; flex-direction: column; min-height:100vh">
<div>Sidebar</div>
<div style="flex-grow: 2">All my views</div> // Container of the main content of my app
</div>
Result:
See what's wrong? Why is not centered like it was on desktop?
That's because the login div, the one nested into the content container that has a flex-grow: 2
is not filling up the entire height anymore:
Even though the container is still stretching and the div has a height: 100%
?? Why this behavior??
Well after HOURS of trying to understand what was going on, I tried using height: 100vh
instead of min-height: 100vh
on the root container and it freaking works.
Why the hell does it work now? min-height
and height
have the same effect, they set specific height for the root container. I tried both and the result on my desktop view is the same, it's only on mobile viewport, when my root container has a flex-direction: column
, that the login component doesn't fill up the height anymore.
Btw I don't want to use height: 100vh
! What if the content is higher than 100vh? I don't want an ugly overflow, that's why I always use min-height
. I'm stuck, how can I fix that?