Asking
Asking

Reputation: 4200

Add styles to all nested elements using Tailwindcss

I have this markup:

<p class='[&_a]:text-[red]'><a>hi</a> world</p>

This code adds styles to all a tags within p tag, but i want to add the class to all elements regardless of the fact that it is a, 'div`,or anything else. I tried to do this:

<p class='[&_*]:text-[red]'><a>hi</a> world</p>

but it does not work.

How can I achieve what I described above?

Upvotes: 2

Views: 2988

Answers (3)

asad minhas
asad minhas

Reputation: 281

Thanks me later!

[&>*]:text-gray-800

Upvotes: 0

If I understand correctly, you want to style all children of your <p> element. CSS styles are inherited by all children elements by default. You can use text-red class directly on your <p> element without any variant.

Upvotes: 0

Tom
Tom

Reputation: 5667

"world" is not a child element. If you want to color it, you should use this class :

class="text-[red] [&_*]:text-[red]"

Upvotes: 3

Related Questions