在本章中,讓我們學(xué)習(xí)SASS 的注釋。注釋是放置在源代碼中不可執(zhí)行的語句。注釋使源代碼更易于理解。SASS支持兩種類型的注釋。
多行注釋 - 這些使用 /*和*/ 寫入。多行注釋都保留在CSS輸出。
單行注釋 - 這些是使用//跟著注釋。單行注釋不會保留在CSS輸出。
實(shí)例
下面的例子演示了SCSS 文件中使用注釋:
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>SASS注釋 - www.yiibai.com</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<h1>Welcome to YiiBai</h1>
<a href="http://www.yiibai.com/">Yiibai Yiibai</a>
</body>
</html>
接下來創(chuàng)建一個(gè)文件: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監(jiān)視文件,并隨時(shí)使用下面的命令更新SASS文件修改CSS:
sass --watch C:\Ruby22-x64\style.scss:style.css
接著執(zhí)行上面的命令,它會自動(dòng)創(chuàng)建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; }
輸出
讓我們來執(zhí)行以下步驟,看看上面的代碼輸出:
保存上面的html代碼在 sass_comments.html 文件。
在瀏覽器中打開該HTML文件,得到輸出結(jié)果如下。
原文來自:易百