Less注釋

注釋使得代碼清晰,使用戶能夠方便理解。您可以在代碼中使用這兩種注釋:區塊樣式和內聯注釋,但是當你編譯 Less 代碼,單行注釋將不會出現在CSS檔。

示例

下麵的例子演示了Less檔中使用的注釋:
<html>
<head>
   <title>Less Comments</title>
   <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
   <h1>Example using Comments</h1>
   <p class="myclass">LESS enables customizable, manageable and reusable style sheet for web site.</p>
   <p class="myclass1">It allows reusing CSS code and writing LESS code with same semantics.</p>
</body>
</html>
接下來,創建檔 style.less。

style.less

/* It displays the
green color! */
.myclass{
color: green;
}
// It displays the blue color
.myclass1{
color: red;
}
你可以編譯 style.less 檔使用以下命令來生成 style.css 檔:
lessc style.less style.css
接著執行上面的命令,它會自動創建 style.css檔,下麵的代碼:

style.css

/* It displays the
green color! */
.myclass {
  color: green;
}
.myclass1 {
  color: red;
}

輸出

讓我們來執行以下步驟,看看上面的代碼工作:
  • 保存上面的 html 代碼在 comments.html 檔。
  • 在流覽器中打開該HTML檔,得到如下輸出顯示。


上一篇: Less作用域 下一篇: Less導入