So I am just fiddling for some curiosity on jsFiddle. When I apply style on below HTML:
<p>Hello World</p>
Styles:
p {
position:relative;
top: 50%;
left: 50%;
}
The Hello World comes to the center horizontally but not vertically.
But , when I change the position from relative
to absolute
,
the element aligns horizontally and vertically as well.
As I understand positioning, top: 50%
should change the top of a block element.
Anything I am missing here (conceptually or otherwise)?
p {
position:relative;
top: 50%;
left: 50%;
}
<p>Hello World</p>