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 Comments
廣告