Ghost
Ghost

Reputation: 63

What CSS selector to use for multiple classes targeting one HTML element?

This is what I have:

nav .class1, nav .class2, nav .class3 {property: value;}


This is what I want (or something similar):

nav (something) .class1, .class2, .class3 {property: value;}

Upvotes: 0

Views: 56

Answers (1)

António Almeida
António Almeida

Reputation: 10127

If you could change your html, you could add a class to the elements you want to match, like this:

HTML:

<nav>
    <div class="class1 to-match"></div>
    <div class="class2 to-match"></div>
    <div class="other"></div>
</nav>

CSS:

nav > .to-match {property: value;}

If you can't change the HTML the only way to do this is with a preprocessor.

Upvotes: 1

Related Questions