1

Order of the class names that are added using class attribute on a HTML element matters?

Say I have two elements like:

<div class="class1 class2"></div>
<div class="class2 class1"></div>

And we have classes defined like:

.class1 {
   color:#fff;
   ....
}
.class2{
   color:#333;
   ....
}

What is the effect of the classes order here? Which color wins for both divs? Thanks.

Ramson
  • 229
  • 4
  • 12
  • 2
    This question has been asked before, see it here: http://stackoverflow.com/questions/3066356/multiple-css-classes-properties-overlapping-based-on-the-order-defined – Llogari Casas May 07 '15 at 22:31

1 Answers1

2

Only the order of the rules in the CSS matters.

In your case CSS works like this:

  1. Apply color:#fff; to all .class1 elements
  2. Then: apply color:#333; to all .class2 elements

So both divs will have color:#333;.

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75