235

i have this elements

<div class="a b"></div>
<div class="b"></div>
<div class="a"></div>

I want apply to element with class a and b the color #666. How can I do this with CSS?

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Luca Romagnoli
  • 12,145
  • 30
  • 95
  • 157

2 Answers2

408

You can chain class selectors without a space between them:

.a.b {
     color: #666;
}

Note that, if it matters to you, IE6 treats .a.b as .b, so in that browser both div.a.b and div.b will have gray text. See this answer for a comparison between proper browsers and IE6.

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
30

Just chain them together:

.a.b {
  color: #666;
}
htanata
  • 36,666
  • 8
  • 50
  • 57