5. 注释 / / 与 // (Comments: / / and //)

Sass 支持标准的 CSS 多行注释 / /,以及单行注释 //,前者会被完整输出到编译后的 CSS 文件中,而后者则不会,例如:

  1. /* This comment is
  2. * several lines long.
  3. * since it uses the CSS comment syntax,
  4. * it will appear in the CSS output. */
  5. body { color: black; }
  6. // These comments are only one line long each.
  7. // They won't appear in the CSS output,
  8. // since they use the single-line comment syntax.
  9. a { color: green; }

编译为

  1. /* This comment is
  2. * several lines long.
  3. * since it uses the CSS comment syntax,
  4. * it will appear in the CSS output. */
  5. body {
  6. color: black; }
  7. a {
  8. color: green; }

! 作为多行注释的第一个字符表示在压缩输出模式下保留这条注释并输出到 CSS 文件中,通常用于添加版权信息。

插值语句 (interpolation) 也可写进多行注释中输出变量值:

  1. $version: "1.2.3";
  2. /* This CSS is generated by My Snazzy Framework version #{$version}. */

编译为

  1. /* This CSS is generated by My Snazzy Framework version 1.2.3. */