I want to make all my content/elements in tag to be centered of the browser or viewport.
I did this initially:
body {
background-color: hsl(212, 45%, 89%);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
But my is not at the center vertically. You can refer here for the image.
However, after I added height: calc(100vh - 1px);
to my code, then only it will be at the center of the browser/viewport perfectly.
Full code:
body {
background-color: hsl(212, 45%, 89%);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: calc(100vh - 1px);
}
You can referhere for the image and can see the content is in the center now.
My understanding is, with display:flex, justify-content: center, align-items: center, I would be able to make all the child elements to be centered. Obviously, my understanding is wrong.
Can anyone explain this?
Thank you in advance!