I encountered a little problem while creating a modal in Angular. The container box has position: fixed
, width: 100vw
and height: 100vh
in order to cover all the screen. The content has display: flex
to align its own content vertically. But the two properties don't look like working properly if used together.
Here is a stackblitz snippet to reproduce the bug.
Troubles start when I resize the browser vertically and the content doesn't fit anymore in the viewport. The scrollbar appears as expected, but in place of starting from the top, it starts from the middle of the element, and I tried inspecting it for hours without understanding why it does happen.
How can I fix it keeping display: flex
?
Here is some relevant code:
:host { /* modal container*/
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
z-index: 100;
align-items: center;
justify-content: center;
}
.box-container { /* div used only to make the scrollbar appear */
height: 100%;
display: flex; /* comment this line to make it work */
align-items: center;
justify-content: center;
overflow-y: auto;
overflow-x: hidden;
}
EDIT
I'm still looking for a solution, read the comment