LESS - 匯入



描述

它用於匯入LESS或CSS檔案的內容。

示例

以下示例演示了在LESS檔案中使用匯入:

<html>
   <head>
      <title>Less Importing</title>
      <link rel = "stylesheet" type = "text/css" href = "style.css" />
   </head>

   <body>
      <h1>Example using Importing</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>
      <p class = "myclass2">LESS supports creating cleaner, 
      cross-browser friendly CSS faster and easier.</p>
   </body>
</html>

現在建立 *myfile.less* 檔案。

myfile.less

.myclass {
   color: #FF8000;
}

.myclass1 {
   color: #5882FA;
}

現在建立 *style.less* 檔案。

style.less

@import "https://tutorialspoint.tw/less/myfile.less";
.myclass2 {
   color: #FF0000;
}

*myfile.less* 檔案將從路徑 https://tutorialspoint.tw/less/myfile.less 匯入到 *style.less* 中。

您可以使用以下命令將 *style.less* 檔案編譯成 *style.css*:

lessc style.less style.css

執行上述命令;它將自動建立包含以下程式碼的 *style.css* 檔案:

style.css

.myclass {
   color: #FF8000;
}

.myclass1 {
   color: #5882FA;
}

.myclass2 {
   color: #FF0000;
}

輸出

按照以下步驟檢視上述程式碼的工作方式:

  • 將上述HTML程式碼儲存在 **importing.html** 檔案中。

  • 在瀏覽器中開啟此HTML檔案,將顯示以下輸出。

Less Importing
廣告