- Browsers are natively responsive and mobile-first.
- Layout should be effective at every size.
- Visibility, font sizes, and spacing, etc. should be effective at every size.
- Use responsive units.
- Write styles mobile-first.
- Use flexbox and CSS grid to make the browser do math for you.
- Use DRY programming principles with CSS variables, calc() functions, and mixins.
- Encapsulate styles with a naming convention such as BEM.
- Identify reuseable components. (Can you map them 1:1 to your React components?)
- Encapsulate their styles using BEM.
- Sit style partials alongside the component they style using webpack or SCSS partials so you know what CSS belongs with what component.
- Remove extraneous styles from affecting your newly encapsulated component.
- Set up a linter to keep syntax and code style consistent.
- Identify variables and make your CSS DRY. (Space, family stacks, colors, breakpoints, and font weights: all good candidates for variables.)
- We identify reuseable UI components
- We encapsulate their styles using BEM
- We sit style partials alongside the component they style using partials so we know which styles belong with which component
- We use a linter to keep syntax and code style consistent here
- We identify variables to make our CSS Dry:
- Spacing
- Breakpoints
- Colors
- etc.
- "We sit style partials alongside the component they style using partials so we know which styles belong with which component"
This can get pretty complex if you're building a UI library: css modules are a sophiticated way of preventing style conflicts
- "Use DRY programming principles with CSS variables, calc() functions, and mixins"
PostCSS marries new-spec CSS goodness (native CSS variables, the calc() function, and whatever else hits the spec in the future) with the stuff we love from Sass, like mixins and nesting. (How dirty was my style.css file because I couldn't nest?)