在本章中,我們來研究Sass 注釋。注釋是放在源代碼中的不可執(zhí)行語句。注釋使源代碼更容易理解。Sass支持兩種類型的注釋。
多行注釋 - 使用/ *和* /寫入。多行注釋保存在CSS輸出中。
單行注釋 - 這些是使用 // 和注釋寫成的。單行注釋不會(huì)保留在CSS輸出中。
下面的示例演示了在SCSS文件中使用注釋:
<html> <head> <title>SASS comments</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <h1>Welcome to TutorialsPoint</h1> <a href="//hgci.cn/">TutorialsPoint</a> </body> </html>
接下來,創(chuàng)建文件 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文件更改時(shí)更新CSS:
sass --watch C:\ruby\lib\sass\style.scss:style.css
接下來執(zhí)行上面的命令,它將用下面的代碼自動(dòng)創(chuàng)建 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文件,將顯示如下輸出。
要研究多行注釋中的插值,請(qǐng)單擊此鏈接。
更多建議: