Carven
Carven

Reputation: 15648

Targeting a class applied to a div that has multiple classes

Suppose I have a few classes applied to a div like this:

<div class="classA classB classC">...</div>

In my CSS, I want to target and write styles for those classC that have classB applied to the same div as well.

If I use this:

.classB .classC {...}

This will only work if there is another child div, and is not what I want.

So, how can I target those classC that has classB applied to the same div?

Upvotes: 0

Views: 83

Answers (3)

Bram Vanroy
Bram Vanroy

Reputation: 28437

You can stack them. Like so.

div.classA.classB.classC

This would work with IDs too, even though it is less applicable.

div#unique-1.classA.classB

Upvotes: 1

NicholasJohn16
NicholasJohn16

Reputation: 2409

Like this:

.classB.classC { }

No spaces between the classes will target all elements with both.

Upvotes: 1

Alex Art.
Alex Art.

Reputation: 8781

Use div.classC.classB as a selector

Upvotes: 1

Related Questions