理想上,**任何**?CSS 規則集之前都應該使用 C 風格注釋來解釋 CSS 塊的核心。這個注釋也要記錄對規則集特定部分編號的解釋。比如:
~~~
/**
* Helper class to truncate and add ellipsis to a string too long for it to fit
* on a single line.
* 1\. Prevent content from wrapping, forcing it on a single line.
* 2\. Add ellipsis at the end of the line.
*/
.ellipsis {
white-space: nowrap; /* 1 */
text-overflow: ellipsis; /* 2 */
overflow: hidden;
}
~~~
基本上,任何不能明顯看出意義的地方都應該注釋,但不要隨處注釋。記住不要**注釋太多**,掌握尺度讓每一處注釋都有意義。
當注釋 Sass 的一個特定部分時,應該使用 Sass 單行注釋而不是 C 風格的注釋塊。這么做將不會輸出注釋,即使是在開發時的擴展模式。
~~~
// Add current module to the list of imported modules.
// `!global` flag is required so it actually updates the global variable.
$imported-modules: append($imported-modules, $module) !global;
~~~
## 擴展閱讀
* [CSS Guidelines’ Commenting section](http://cssguidelin.es/#commenting)
- 關于作者
- 貢獻
- 關于Sass
- Ruby Sass Or LibSass
- Sass Or SCSS
- 其他預編譯器
- 簡介
- 為什么需要一個樣式指南
- 免責聲明
- 核心原則
- 語法格式
- 字符串
- 數字
- 顏色
- 列表
- Maps
- CSS規則集
- 聲明順序
- 選擇器嵌套
- 命名約定
- 常量
- 命名空間
- 注釋
- 標示注釋
- 文檔
- 結構
- 組件
- 7-1模式
- Shame文件
- 響應式設計和斷點
- 命名斷點
- 斷點管理器
- 媒體查詢用法
- 變量
- 作用域
- !default標識符
- !global標識符
- 多變量或maps
- 擴展
- 混合宏
- 基礎
- 參數列表
- 混合宏和瀏覽器前綴
- 條件語句
- 循環
- Each
- For
- While
- 警告和錯誤
- 警告
- 錯誤
- 工具
- Compass
- 柵格系統
- SCSS-Lint
- 總結概要