I want to style an <a>
tag inside a using Tailwind CSS. I want to add the style via the parent <ul>
tag. I tried [&>li>a]
, but it doesn’t work as expected.
Here is my HTML structure:
<ul class="flex items-center [&>li>a]:hover:text-white">
<li class="flex items-center">
<div>
<a href="/"> Route3 </a>
</div>
<a href="/"> Route2 </a>
<span class="hero-chevron-right separator-icon"></span>
</li>
</ul>
How can I achieve this styling correctly? I don’t want to change any config or add new selectors.
2
Answers
You can accomplish this by styling each of the anchor tags in this way:
The way you’ve written it, the :hover applies to the ul. You want
[&>li_a:hover]:text-white