Search code examples
htmlcsscss-selectors

Styling when element has two classes


I have been looking at the w3 page on css selectors and have not found any promising leads, so I thought I would ask...

Is there a way to style a single element with two classes differently than if it was one class?

Example:

a.foo {
  color: red;
}

a.bar {
  color: yellow;
}

a.foo.bar {
  color: orange;
}
<a class="foo">Red</a>
<a class="bar">Yellow</a>
<a class="foo bar">Orange</a>


Solution

  • You just answered yourself. Be wary of the IE6 bug.