How to select an element with 2 classes

Luca Romagnoli picture Luca Romagnoli · Feb 25, 2011 · Viewed 140.6k times · Source

Possible Duplicate:
CSS Selector that applies to elements with two classes

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?

Answer

BoltClock picture BoltClock · Feb 25, 2011

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.