Is there a way to select an element with CSS based on the value of the class attribute being set to two specific classes. For example, let's say I have 3 divs:
<div class="foo">Hello Foo</div>
<div class="foo bar">Hello World</div>
<div class="bar">Hello Bar</div>
What CSS could I write to select ONLY the second element in the list, based on the fact that it is a member of both the foo AND bar classes?
Chain both class selectors (without a space in between):
If you still have to deal with ancient browsers like IE6, be aware that it doesn't read chained class selectors correctly: it'll only read the last class selector (
.bar
in this case) instead, regardless of what other classes you list.To illustrate how other browsers and IE6 interpret this, consider this CSS:
Output on supported browsers is:
Output on IE6 is:
Footnotes:
foo
.foo
andbar
.bar
.bar
.bar
, regardless of any other classes listed.