In case of Tailwind CSS
Read the descriptive and a very brief documentation entry here: Using arbitrary variants.
As I can see you need to change the color of all the <a>
links no matter how deeply they reside in the <cards>
. Use an underscore between &
and a
selectors - [&_a]:text-black
. This translates to:
.card--primary {
/* arbitrarily nested <a> links */
a {
color: black
}
}
On the other hand the Tailwind directive with >
between &
and a
=> [&>a]:text-black
would result in this css (only the direct child <a>
nodes would be styled):
.card--primary {
/* direct-child <a> links */
> a {
color: black
}
}
Recap: the resulting Tailwind HTML for your case:
<div className="card--primary [&_a]:text-black" >
<a></a> !-- will be black
<div>
<a></a> !-- will be black
</div>
<div/>
<div className="card--danger [&_a]:text-white" >
<a></a> !-- will be white
<div>
<a></a> !-- will be white
</div>
<div/>
That's it. I hope it is helpful.