215

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
  • 211,628
  • 17
  • 234
  • 311
Luca Romagnoli
  • 11,921
  • 30
  • 91
  • 155

2 Answers2

373

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
  • 11,565
  • 7
  • 67
  • 91
BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
27

Just chain them together:

.a.b {
  color: #666;
}
htanata
  • 35,696
  • 8
  • 48
  • 56