-
I'm trying to combine arbitrary variants and data-attributes selectors to style a child based upon the parent's data-attribute value. I've tried all manner of combinations, but I can't seem to get it the right syntax. Given the following: <div data-hello="world">
<div>Child</div> <!-- style me -->
</div> The value of the data-attribute will change, and I need to conditionally style the child div based upon the value in the parent's data attribute. What is the correct way to style a child based on a parent's data attribute value? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can use <div data-hello="world" class="group">
<div class="group-data-[hello=world]:text-red-500">Is red</div>
</div>
<div data-hello="foo" class="group">
<div class="group-data-[hello=world]:text-red-500">Is not red</div>
</div> See this in action on this Tailwind Play. |
Beta Was this translation helpful? Give feedback.
You can use
group
variant combined with thedata-
variant:See this in action on this Tailwind Play.