Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MDN confusing concept for top property

.text {
  position: relative;
  top: 50%;
  left: 50%;
  }
<a class="text">Hello</strong>

Top

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 .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

MDN links to the specification.

Look carefully at what a percentage length means in this context:

The inset is a percentage relative to the containing block’s size in the corresponding axis (e.g. width for left or right, height for top and bottom). For sticky positioned boxes, the inset is instead relative to the relevant scrollport’s size. Negative values are allowed.

The height of the containing block is auto (the default) and when a percentage is calculated of auto you get 0.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading