by nickand · 15y ago · 0 comments
Also who says you need to copy the color every time you use it?
This is how it works. If you have one important property that you want to change everywhere then you use the most specific target class necessary for each of those classes in a comma separated list attached to only that property then you can change them all later or add new classes to them.
.class, .anotherClass, .yetSomeOther .moreSpecificTarget {color:blue;}
Also if you want to simulate if / then statements then you write your most general classes first followed by your more specific classes. So:
.blue {color:blue;}
.blue.darker {color:rgb(4,4,179)};
It's even better than a conditional. It's a switch.
CSS won't let you do any of this natively.
.class, .anotherClass, .yetSomeOther .moreSpecificTarget {color:blue;}
That's no better, because you have to duplicate your selectors. You end up with stuff like:
.class, .anotherClass, .yetSomeOther .moreSpecificTarget {color:blue;}
.yetSomeOther .moreSpecificTarget {border: pink solid 1px;}
.anotherClass, .yetSomeOther {margin: 5px;}
.yetSomeOther .moreSpecificTarget {margin: 1px;}
Basically if you follow this model you have to have a line for every single property you want to style. It's unmaintainable, and increases the size of your CSS files.