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

<a> element in <p> messes up in Chrome

The following code causes the outer <a> tag to show twice and splits the contents of the <p> tag:

  <a href="https://five-pillars-simulator.luisafk.repl.co" target="fivepillarssmiluator" class="card dfc tc mw m40 cb tdn">
    <h2 class="card-title">
      Five Pillars Simulator
    </h2>
    <p class="card-body tj">
      A History Project me and <a href="https://replit.com/@gabrielo4">Gabe</a> made for a school History project.
    </p>
  </a>

It seems the problem is the <a> tag inside the <p> because if I remove it it shows correctly.

Current behaviour:
enter image description here

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

Expected behaviour (or without the second <a>):
enter image description here

The elements in Chrome DevTools with the messed up behaviour:
enter image description here

>Solution :

The problem is that you cannot have nested <a> tags.

You inner <a> tag links to the same target, so there is no reason to add an extra <a> tag.

If you want to style them differently consider using for instance a <span> for the inner "link"

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