Vinith Almeida
Vinith Almeida

Reputation: 1471

Targetting a class with multiple classes on the parent

Here's the HTML,

<body class="home page page-id-13">
   <div class="targetthis">
   </div>
</body>

I want to target the class "targetthis" only when the body class has both "home" and "page" on it.

Upvotes: 0

Views: 42

Answers (3)

user1403333
user1403333

Reputation: 98

You could just write firstClass.secondClass.thirdClass .childNodeClass

https://css-tricks.com/multiple-class-id-selectors/

Upvotes: 1

Suresh Ponnukalai
Suresh Ponnukalai

Reputation: 13988

Use both the classes in your target CSS selector like below.

 body.home.page .targetthis
 {
   background-color:red;
 }

DEMO

Upvotes: 1

Pete
Pete

Reputation: 58422

Try this

body.home.page .targetthis

by removing the spaces you are saying that you want an element with both classes, and by using the body, you are saying you are wanting the body element with both classes

If you only want targetthis as the direct child then you need to add the >

More info on multiple class / id selectors

Upvotes: 4

Related Questions