Reasonable System for CSS Stylesheet Structure
github.com
github.com
The examples are great and realistic but they will inevitably break down in any project with just a moderate amount of complexity. When this happens I see people decide that they've done something wrong and think they either need to restructure the UI to fit the guidelines or find a different set of guidelines to fit their project. Both are wrong.
After years of studying these guidelines and trying to perfect the perfect, most efficient, small, and understandable set of CSS styles I've come to the realization that we need to simply accept that there are going to be exceptions and that's okay. Yes, think in components, give classes sane names, don't use ID attributes, etc. but also know that at some point you're probably going to have to break a rule and it's not the end of the world. Think about the problem for a few minutes but don't waste your time trying to shoehorn your front end code to fit a set of guidelines so you can feel superior because of your strict adherence to RCSS or SUITCSS or whatever. There are more pressing issues than a few unused or single use classes. If you can follow the rules more than 80% of the time then I say you're as close to perfect as you'll ever be. Anything else is reaching for an impossible standard.
It's funny that the stricter you adhere to some of these guidelines the less productive you become as you spend more time thinking about how to create components so they fit the rules rather than getting the damn styles to look however you want.
My point being this: I love all the different philosophies and think they're all worth studying but let's be realistic when it comes time to implement stuff.
Using webpack's css-loader changes the game completely as pointed out by Mark Dalgleish here:
https://medium.com/seek-ui-engineering/the-end-of-global-css...
Writing maintainable CSS is now encouraged, not by careful adherence to a naming convention, but by style encapsulation during development.
I'm sure there will continue to be more JS solutions to getting rid of CSS naming conventions, since it seems everything is being done with JS these days.
CSS modules is a cool idea but I don't think there's anything wrong with CSS as it stands today. When you work in any language you need to understand and work with the language you have and I think that a lot of criticism of CSS boils down to "CSS doesn't work like this other language/paradigm I know and like".
No, CSS isn't a programming language, but that doesn't mean it can't use functionalities that are typical of programming languages - just look at variables, functions, arrays, maps and other features that preprocessors like SASS have brought us.
While some approaches are a matter of taste/habit, I think there's an extremely wide consensus that having everything available in global scope is bad.
If the global namespace really is by design, then why are we adopting conventions (such as the one in this very topic) that mostly aim to defeat it? Prefixing class names to apply them only to a specific component is nothing but a primitive way of limiting scope.
I'm wondering what's the merit/advantages of using css-modules over using Shadow DOM to limit the scope of CSS rules.
In these cases you would fully encapsulate CSS, HTML, and JS on a per-component basis.
https://github.com/suitcss/suit/blob/master/doc/naming-conve...
See https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity...
.parent .child .element {
is bad for performance — thus BEM's: .parent--child__element {Fix the UX and the CSS performance will magically fix itself.
It would also stops you from having general styles declarations.
You couldn't do .button{color:red;border: 1px solid white;} and then .box>.button{width:100%;} unless you make your markup <span class="button pricebox--box__button"> and that would be pretty ugly, wouldn't it?
Correct me if I am wrong.
.parent>.child>.element. .parent__child-element {
?