I learnt a new (new to me) way of centering divs from an online resource. I can not get hold of the author, so please explain what exactly is happening here.
<header class="header">
<div class="header-box">
<h1>
Lorem Ipsum <br>
Dolor sit amet
</h1>
</div>
</header>
.header {
position: relative;
height: 100vh;
background-image: linear-gradient(
to right bottom,
rgba(17, 63, 112),
rgba(253, 135, 31));
background-position: top;
}
.header-box {
position: absolute;
top: 50%; /*This and next line*/
left: 50%;
transform: translate(-50%, -50%); /*and this*/
}
h1 {
text-align: center;
}
How exactly the Transform property is aligning the div in center perfectly when the position property pushed it away?