Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Architecture

CSS Architecture

danielwang

July 09, 2021
Tweet

More Decks by danielwang

Other Decks in Technology

Transcript

  1. Why? Evolving Design Growing Complexity Repetitive Design Technical Difficulties •

    Source order affects application order • Specificity is hard to deal with • CSS operate in global scope
  2. CSS Methodologies BEM (2015) Block, Element, Modifier SMACSS (2012) Scalability

    and modular architecture of CSS OOCSS (2011) Object Oriented CSS. Separation of structure and design. Separation of container and content Atomic CSS (2017) Utility First, Functional CSS CSS-in-JS • CSS Modules • Styled-components • Emotion
  3. BEM

  4. CSS at Scale Is all about picking a reasonable subset

    of the CSS language Deciding to not do a whole lot of things that CSS can do But we do this to make our app more maintainable
  5. Proposed approach Utility First + Modular CSS Use global scoped

    utility classes from CAD CSS framework via CDN or package Keep contextual CSS in local scoped in your app
  6. Defining Atomic CSS Atomic CSS is the approach to CSS

    architecture, like inline styles, offers single-purpose units of style, but applied via classes on HTML.
  7. Utility Classes Atomic CSS basically means that you have a

    ton of tiny, single purpose classes that are named based on their visual function. • Text sizes, colors, and weights • Shadows • Borders • Background colors • Flexbox utilities • Padding and margin helper • Width & Heights • Positions and alignments one class = one job .mt-0 { margin-top: 0; } .pr-1 { padding-right: var(--spacer-1); } .bg-dark { background-color: var(--bg-dark); } .text-red { color: var(--red); }
  8. Approach • Transition from "semantic" approach to "functional CSS" (Atomic

    CSS) • Content-agnostic components + utility classes • Mobile first
  9. Pros • Only define the classes once • Enforced UI

    consistency • CSS Reusability and Scalability • Composable • Developers don’t need write CSS code most of the time • Cross devices and browsers compatibility
  10. Cons • Developers still need to learn CSS • Developers

    have to remember utilities and check the tech docs • HTML pollution • It doesn’t work well with micro interaction and animation
  11. CAD v1.1 includes: + Root CSS variables + Grid system

    + Pre build components + Utility classes
  12. UI code strategy 1. Write semantic HTML 2. Use utility

    Classes first 3. Write modular CSS