How to add conditional style based on the parent class? #5363
-
For instance, I have multiple list items, I want to change the style of the active list item only. In CSS i can achieve it like this: li { li.active { How we can acheive this in tailwind css? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
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 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. |
Beta Was this translation helpful? Give feedback.
-
You can do it like this: <ul class="text-red-700">
<li>Option 1</li>
<li>Option 2</li>
<li class=" active:text-blue-700">Option 3</li>
</ul> Or you can do it with |
Beta Was this translation helpful? Give feedback.
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 likeOr 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.