任何超过 1000 行的 CSS 代码,你都曾经历过这样的体验:
xxoo class,会造成冲突吗?Reasonable System for CSS Stylesheet Structure 的目标就是解决以上问题,它不是一个框架,而是通过规范,让你构建更健壮和可维护的 CSS 代码。

从 Components 的角度思考,将网站的模块都作为一个独立的 Components。
Components 最少以两个单词命名,通过 - 分离,例如:
.like-button).search-form).article-card)
Elements 是 Components 中的元素
Elements 的类名应尽可能仅有一个单词。
 .search-form {
    > .field { /* ... */ }
    > .action { /* ... */ }
  }
对于倘若需要两个或以上单词表达的 Elements 类名,不应使用中划线和下划线连接,应直接连接。
  .profile-box {
    > .firstname { /* ... */ }
    > .lastname { /* ... */ }
    > .avatar { /* ... */ }
  }
任何时候尽可能使用 classnames。标签选择器在使用上没有问题,但是其性能上稍弱,并且表意不明确。
  .article-card {
    > h3    { /* ✗ avoid */ }
    > .name { /* ✓ better */ }
  }

Components 和 Elements 可能都会拥有 Variants。
Variants 的 classname 应带有前缀中划线 -
  .like-button {
    &.-wide { /* ... */ }
    &.-short { /* ... */ }
    &.-disabled { /* ... */ }
  }
  .shopping-card {
    > .title { /* ... */ }
    > .title.-small { /* ... */ }
  }
为什么使用中划线作为变体的前缀?
Elements_ 或 - 开头
Components 应该在不同的上下文中都可以复用,所以应避免设置以下属性:
头像和 logos 这些元素应该设置固定尺寸(宽度,高度...)。
倘若你需要为组件设置定位,应将在组件的上下文(父元素)中进行处理,比如以下例子中,将 widths 和 floats 应用在 list component(.article-list) 当中,而不是 component(.article-card) 自身。
  .article-list {
    & {
      @include clearfix;
    }
    > .article-card {
      width: 33.3%;
      float: left;
    }
  }
  .article-card {
    & { /* ... */ }
    > .image { /* ... */ }
    > .title { /* ... */ }
    > .category { /* ... */ }
  }
当出现多个嵌套的时候容易失去控制,应保持不超过一个嵌套。
  /* ✗ Avoid: 3 levels of nesting */
  .image-frame {
    > .description {
      /* ... */
      > .icon {
        /* ... */
      }
    }
  }
  /* ✓ Better: 2 levels */
  .image-frame {
    > .description { /* ... */ }
    > .description > .icon { /* ... */ }
  }
-是一坨糟糕的玩意:其实你可以选择性的使用,只要将 Components, Elements, Variants 记在心上即可。aleter 。但其实你可以使用后缀,使其意识更加明确。比如块级元素:
或行内级元素
RSCSS 与其他 CSS 模块组织系统相似的概念
| RSCSS | BEM | SMACSS | 
|---|---|---|
| Component | Block | Module | 
| Element | Element | ? | 
| Layout | ? | Layout | 
| Variant | Modifier | Theme & State | 
Components 的角度思考,以两个单词命名(.screenshot-image)Components 中的 Elements,以一个单词命名(.blog-post .title)Variants,以中划线-作为前缀(.shop-banner.-with-icon)Components 可以互相嵌套