Skip to content

How to add conditional style based on the parent class? #5363

Answered by lukewarlow
gursewak-sohi asked this question in Help
Discussion options

You must be logged in to vote

Going to need more context as to your setup. But you would add text-red-500 (or whatever colour you want) and then conditionally add text-blue-500 (or whatever colour you want) to the "active" li using javascript.

Alternatively you can make use of Tailwind's @apply and do something like

li { 
    @apply text-red-500;
}

li.active {
     @apply text-blue-500;
}

Or do a mixture of both. It really depends on your setup and your preferences.

If I've misunderstood your question, I would try and add more context to your question to explain the exact thing you're trying to do and your overall tech stack as that might help tailor answers to your situation.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@gursewak-sohi
Comment options

@lukewarlow
Comment options

Answer selected by gursewak-sohi
Comment options

You must be logged in to vote
2 replies
@lukewarlow
Comment options

@gursewak-sohi
Comment options

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