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

Tailwind: color children links red

I’ve got some DOM:

<div>
  <p>
    <a>ham</a>
  </p>
</div>

I want to add a class attribute to the DIV to turn all the children a tags red. I know I can do <div class="[&>p>a]:text-red-500"> but the a tags can be at any arbitrary depth within the <div>. Anyone know the syntax to make the links red?

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 :

You could consider using a selector in the arbitrary variant that does not have any direct descendent operators:

<script src="https://cdn.tailwindcss.com/3.3.2"></script>

<div class="[&_a]:text-red-500">
  <p>
    <a>ham</a>
  </p>
</div>
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