Skip to content

Need help selecting child based on parent data attribute value #9879

Answered by wongjn
danofpaco asked this question in Help
Discussion options

You must be logged in to vote

You can use group variant combined with the data- variant:

<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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@danofpaco
Comment options

@logemann
Comment options

@wongjn
Comment options

Answer selected by danofpaco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants