List both classes (without a space in between):
.foo.bar {
/* Styles for element(s) with foo AND bar classes */
}
Note that IE6 doesn't support this, it'll select all elements with the last class (.bar
in this case) instead, regardless of what other classes you list.
To illustrate how other browsers and IE6 interpret this, consider this CSS:
* {
color: black;
}
.foo.bar {
color: red;
}
Output on supported browsers is:
<div class="foo">Hello Foo</div> <!-- Not selected, black text [1] -->
<div class="foo bar">Hello World</div> <!-- Selected, red text [2] -->
<div class="bar">Hello Bar</div> <!-- Not selected, black text [3] -->
Output on IE6 is:
<div class="foo">Hello Foo</div> <!-- Not selected, black text [1] -->
<div class="foo bar">Hello World</div> <!-- Selected, red text [2] -->
<div class="bar">Hello Bar</div> <!-- Selected, red text [2] -->
Footnotes:
- Supported browsers:
- Not selected as this element only has class
foo
.
- Selected as this element has both classes
foo
and bar
.
- Not selected as this element only has class
bar
.
- IE6:
- Not selected as this element doesn't have class
bar
.
- Selected as this element has class
bar
, regardless of any other classes listed.