.text {
position: relative;
top: 50%;
left: 50%;
}
<a class="text">Hello</a>
So As per MDN Top link quote:When position is set to relative, the top property specifies the distance the element’s top edge is moved below its normal position.
So as per above quote my understanding is element’s top edge should be moved below its normal position by 50% so why isn’t it happening . Browser is EDGE 11.3 .
2
Answers
MDN links to the specification.
Look carefully at what a percentage length means in this context:
The height of the containing block is
auto
(the default) and when a percentage is calculated ofauto
you get0
.50% of what? The answer is 50% of the parent element. But by default, the parent element is only tall enough to contain the things within it. If you set a height on the parent element to completely fill the vertical height of the page, you will see that this element moves down to 50% of that, like this:
Or a fixed height, like this: