Raanan Avidor Raanan Avidor - 1 year ago 96
CSS Question

CSS style for an element that has class A and class B

I need to style an element that has both class "a" and class "b". How do I do it?

The order the classes appear in the html might vary.

div.a ? div.b{
<div class="a">text not red</div>
<div class="b">text not red</div>
<div class="a b">red text</div>
<div class="b a">red text</div>

Answer Source

That's entirely possible. If you specify two classes on an element (without any spaces), that means that it must have both for the rule to apply.

div.a {
  color: blue;
div.b {
  color: green;
div.a.b {
  color: red;
<div class="a">
<div class="b">
<div class="a b">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download