Previous: IDs Next: Modules →

Conventions

Conventions can be a bone of contention amongst engineers, but what matters most is readability and consistency. With that said, MaintainableCSS has the following convention:

/* Square brackets denote optional parts */
.<moduleName>[-<componentName>][-<state>] {}

Here are some real examples pertaining to a “search results” module:

/* module container/root */
.searchResults {}

/* components of a module */
.searchResults-heading {}

.searchResults-item {}

/* state: such as AJAX loading */
.searchResults-isLoading {}

Each of these class names are semantic. Module, component and state are all delimitted by dashes. Each bit is written in lowerCamelCase.

We will see this convention used in all upcoming chapters.

Share on Twitter
Previous: IDs Next: Modules →

Chapters

  1. 介绍
  2. 语义化(Semantics)
  3. Reuse
  4. IDs
  5. Conventions
  6. Modules
  7. State
  8. Modifiers
  9. Versioning
  10. Javascript
  11. FAQs