Sass 注釋

2018-12-28 16:40 更新

在本章中,我們來研究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 。

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 文件:

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文件,將顯示如下輸出。

Sass Comments

要研究多行注釋中的插值,請(qǐng)單擊此鏈接。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)