详解CSS的Sass框架中代码注释的编写方法
author:一佰互联 2019-04-21   click:257

在 Sass 中注释有两种方式:
1、类似 CSS 的注释方式,使用 ”/* ”开头,结属使用 ”*/ ”
2、类似 JavaScript 的注释方式,使用“//”
Sass 支持标准的CSS多行注释以/* */以及单行注释 //。

两者区别:前者会在编译出来的 CSS 显示,后者在编译出来的 CSS 中不会显示

在尽可能的情况下,多行注释会被保留在输出的CSS中,而单行注释会被删除。 例如:

CSS Code复制内容到剪贴板
  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 { colorblack; }   
  6.     
  7. // These comments are only one line long each.   
  8. // They won"t appear in the CSS output,   
  9. // since they use the single-line comment syntax.   
  10. a { colorgreen; }  

编译为:

CSS Code复制内容到剪贴板
  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.   colorblack; }   
  7.     
  8. a {   
  9.   colorgreen; }  

如果多行注释的第一个字母是 !,那么注释总是会被保留到输出的CSS中,即使在压缩输出模式下。这可用于在你生成的CSS中添加版权声明。

使用插值语句 (interpolation) ,可以将变量值输出到多行注释中,例如:

CSS Code复制内容到剪贴板
  1. $version: "1.2.3";   
  2. /* This CSS is generated by My Snazzy Framework version #{$version}. */  

编译为:

CSS Code复制内容到剪贴板
  1. /* This CSS is generated by My Snazzy Framework version 1.2.3. */