Recently CSS has got a lot of negativity. But I would like to defend it and show, that with good naming convention CSS works pretty well.
My 3 developers team has just developed React.js application with 7668
lines of CSS (and just 2 !important
).
During one year of development we had 0 issues with CSS. No refactoring typos, no style leaks, no performance problems, possibly, it is the most stable part of our application.
Here are main principles we use to write CSS for modern (IE11+) browsers:
- SUIT CSS naming conventions + SUIT CSS design principles;
- PostCSS + CSSNext. Future CSS syntax like variables, nesting, and autoprefixer are good enough;
- Flexbox is awesome. No need for grid framework;
- Normalize.css, base styles and variables are solid foundation for all components;
- No DRY. It does not scale with CSS, just focus on better components;
Please ⭐ this gist if you'd like to support me and hear this ⚡ talk on Reactiveconf 2016 in Bratislava.
Update: video from ReactiveConf 2016
@Pomax thanks for your question. According to HN discussion, it seems like a most controversial principle.
In general I like DRY, but when design requirements constantly evolve, early abstractions can fail. For example:
may occur many times in different parts of the app. It could be a
.container
, but usually this 3 lines are fine, especially when they are a part of component, like everything in React. Also SUIT CSS forces to use only one class likeMyComponent
notgrey container MyComponent
.“no DRY” doesn't mean copy/paste hundreds lines of CSS, just don't be obsessive with repeating yourself with CSS, when class names don't leak to other components.