3 ms·
NO, NO, NO! This advice is completely and utterly wrong. Component thinking is good, it's CSS "best practices" that are backwards and insane, probably because
by stupidcar 10y ago
NO, NO, NO! This advice is completely and utterly wrong.
Component thinking is good, it's CSS "best practices" that are backwards and insane, probably because many of the people who came up with them were designers who weren't educated in the basic principles of writing maintainable code.
You do not want to be in a situation where, when you change a particular class, in order to fix a bug in one UI element, it potentially has side-effects in a myriad of others, none of which you know about.
You do want to be able to come into a codebase and make a fix to a particular element, or component, in your UI, and have absolutely confidence that you have not broken anything else.
How do you do that? By breaking down your UI into independent, encapsulated and composable components. And the component's styles should be specific and encapsulated in the same way as its JS code would be. The fact that CSS allows you to create a big stew of global variables does not mean that it's a good idea to do so. Anyone who tells you otherwise is misleading you.
Follow this "be as unspecific as possible" advice and I guarantee that in a year or so, your CSS will contains thousands of low specificity rules, all applying randomly to different bits of your DOM, with thousands more specific classes to override the unwanted styles that are being picked up from elsewhere.
- Roboprog 10y agoPerhaps a bit more subtlety: Keep global concerns global, and local concerns local. Coloring and font schemes (margins/padding too, I suppose) are usually global, with variations for broad types of components. Sizes / positions of components often end up being very specific, at least in cases where "auto" doesn't work well for what you want.
- manmal 10y agoYes, that's the scope I was talking about, intuitively. I don't understand grandparent's agitation, but yes, sure, local rules should be constrained to their scope.
- manmal 10y agoYes, that's the scope I was talking about, intuitively. I don't understand grandparent's agitation, but yes, sure, local rules should be constrained to their scope.