How to specify the order of CSS classes?

The order in which the attributes are overwritten is not determined by the order the classes are defined in the class attribute, but instead where they appear in the CSS.

.myClass1 {color:red;}
.myClass2 {color:green;}
<div class="myClass2 myClass1">Text goes here</div>

The text in the div will appear green, and not red; because .myClass2 is further down in the CSS definition than .myClass1. If I were to swap the ordering of the class names in the class attribute, nothing would change.

Leave a Comment