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

Why nested inner span is taller than its outer span

Tailwind Playground

Let me use tailwind css for simplicity.

There are two HTML span elements, #outer and #inner.

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

<p class="font-mono">
  abc<span id="outer" class="relative"><span id="inner" class="absolute left-0 top-0">a</span>a</span>defg
</p>

I expect #inner overlaps with #outer, but instead the actual result shows that the painted characters of #inner is slightly lower than #outer:
enter image description here

Then I check the dev console and find outer’s height is 19px, but inner is 24px.

Why does it happen? What’s the correct way to make them overlap with each other?

>Solution :

Try removing left-0 top-0

<p class="font-mono">
  abc<span id="outer" class="relative"><span id="inner" class="absolute">a</span>a</span>defg
</p>

Result:

enter image description here

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