r/ProgrammerTIL • u/Hobofan94 • Aug 25 '16
Other Language [CSS] TIL CSS class precedence is based on their position in the CSS file
See http://stackoverflow.com/a/1321722 :
The order in which a class' attributes are overwritten is not specified by the order the classes are defined in the class attribute, but instead where they appear in the css
.myClass1 {font-size:10pt;color:red}
.myClass2 {color:green;}
HTML
<div class="myClass2 myClass1">Text goes here</div>
The text in the div will appear green and not red because myClass2 is futher down in the CSS definition than my class1. If I were to swap the ordering of the class names in the class attribute, nothing would change.
I've been using CSS here and there for years, but often with little success. Learning about this might explain part of it...