3 ms·
I didn't know there was a name for this method, but it's what I've settled on as well: Namespace the classes by their component's class name, and then override
by karaterobot 7y ago
I didn't know there was a name for this method, but it's what I've settled on as well: Namespace the classes by their component's class name, and then override them, if necessary, in another namespaced context. It's pretty simple, as safe as can be expected, and works well for sites of all sizes.
The only bullet you have to bite is occasionally repeating yourself, but as you say, that part of CSS never really worked well anyway.
If using a pre-processor like Stylus or Sass, you can get a lot of composability with mixins and extensions, if that's what you want, and these can even be cleaner and more flexible than utility classes, because they can use parameters and basic logic.
- ehnto 7y ago> I didn't know there was a name for this method I just made that one up when I started formalizing the method! > The only bullet you have to bite is occasionally repeating yourself, but as you say, that part of CSS never really worked well anyway. I find as well that if you write clean, concise CSS that doesn't have to override anything you get away with far less CSS anyway. So repeating yourself isn't so bad. Similarly, in a project of any longevity, especially if clients are involved, chances are pretty high the things you repeated will eventually diverge. So had you made it DRY you would have to de-compose the coupled components and write it again anyway. With the Contexts, you can make most diverging modifications without ever touching the components, and I feel any more levels of inheritance than that leads to CSS that is more complex than it needs to be.