I'm trying to vertically center a div using
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
however, I've noticed that on first page load, it doesn't work well. The div moves up to the top of the page. On refresh, everything works properly and the div is vertically centered. What can I do to solve this?
To vertically center content of div you can use flex https://css-tricks.com/snippets/css/a-guide-to-flexbox/#article-header-id-7
display: flex;
align-items: center;