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檔案,得到如下輸出顯示。