3 ms·
While I think stylesheet abstraction is a good idea, most programmers (including the author) don't seem to use all the abstraction mechanisms that are already a
by nostrademons 17y ago
While I think stylesheet abstraction is a good idea, most programmers (including the author) don't seem to use all the abstraction mechanisms that are already available in CSS. For example, the change-all-the-colors-on-the-page-at-once problem would go away if webmasters factored all the elements of a given color into a single rule:
span.fl,
span.a,
a.link,
cite { color: #ef88bb; }
body, div.leftnav, div.logo { background-color: #333; }
You're also supposed to rely on the cascade for fonts and stuff: set them once on the body and then let all descendants inherit them.
There're some real problems when you want to set, say, the border color of one element to the color of a bunch of others, but a lot of the CSS maintenance problems I see (and have written ;-)) come from developers just going through the list of elements and writing the properties for each. The cascade was supposed to save you from this; CSS already has a pretty powerful abstraction mechanism.
- chriseppstein 17y agoThat code is not more maintainable. You've centralized a single color but now you've duplicated a selector. The single-rule output mode of Sass is an output optimization mode we plan to add to sass for runtime performance. You should write code the way you think about things and let your tools do the heavy lifting for you.
- nostrademons 17y agoStyles change more often than selector names. If you're using semantic selectors, they shouldn't change much at all. This is a problem with any sort of abstraction. When you write a function in normal code, you duplicate the function name and call signature in exchange for centralizing the body. In Sass, you're presumably duplicating the variable name in exchange for centralizing its definition. The same goes here, except s/variable name/selector/.
- tptacek 17y agoSo now when I want to find out where in the CSS file I need to change the font size of an h3, I have to search through all 127 places where h3 is referenced. All you did was point the problem in a different direction.
- nostrademons 17y agoOr you search for the 3-4ish places where font-size: is mentioned. Most websites have far fewer different text stylings than they have element types. I'm arguing that this is a better direction to point the problem. (I'm also not arguing that abstraction frameworks like Sass are a bad idea, but that you should understand how CSS works before you reach for a framework. I suspect that it never occurred to a lot of folks that they should have long lists of selectors and short lists of properties instead of the reverse, because that's not the syntactic cue they get from the language.)