0

I want to select a specific element identified by three classes. Is this possible? For example, some div element has three classes: alpha, beta and charlie. Some other elements have one or two of these classes also, but I just want my code to affect elements with all three of them, like:

.alpha beta charlie { ... }

Is this possible?

The above example is completely random, I know it doesn't work, but I just wanted to depict what I'm planning to achieve. I'm still trying to learn CSS completely.

Thanks!

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
Benjamin Park
  • 41
  • 1
  • 1
  • 5

3 Answers3

1

You can just do like below DEMO:

CSS:

.alpha.beta.gamma{color:red;}

HTML:

<div class="alpha beta gamma">
   hello
</div>
<div class="alpha beta gamma delta">
   hello
</div>
<div class="alpha beta  delta">
   hello
</div>

This will change color to all the divs which has those three classes together.

Pbk1303
  • 3,702
  • 2
  • 32
  • 47
0

If your CSS rules looks like:

<style>
.alpha { .... }
.beta  {..... }
.charlie {.....}
</style>

And your html like:

<div id=div1 class='alpha beta charlie'><div>
<div id=div2 class='alpha beta charlie'><div>

Then both divs will have all the rules from all 3 classes.

If you then have an additional div like:

<div id=div3 class='alpha beta'><div>

That will only have the rules only from classes called alpha and beta.

Emil Borconi
  • 3,326
  • 2
  • 24
  • 40
0

I believe you are asking how to write your selector using the three class names:

 .alpha.beta.charlie {}

When they are attached, it will style any tag with all 3 of those classes:

<element class="alpha beta charlie">
Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129