LESS - 匯入選項參考關鍵字



描述

@import (reference) 用於匯入外部檔案,但不會將匯入的樣式新增到編譯後的 CSS 檔案中。這在1.5.0 版中釋出。

示例

以下示例演示了在 LESS 檔案中使用reference 關鍵字 −

<html>
   <head>
     <link rel = "stylesheet" href = "style.css" type = "text/css" />
     <title>Import Options Reference</title>
   </head>

   <body>
      <h1>Welcome to Tutorialspoint</h1>
      <p>LESS is a CSS pre-processor that enables customizable, 
      manageable and reusable style sheet for web site.</p>
   </body>
</html>

接下來,建立style.less 檔案。

style.less

@import (reference) "https://tutorialspoint.tw/less/import_reference.less";
p {
   .style1;
}

以下程式碼將從https://tutorialspoint.tw/less/import_reference.less路徑將import_reference.less 檔案匯入到 style.less 中 −

import_reference.less

.style1 {
   color: #A0A0A0;
   font-family: "Comic Sans MS";
   font-size: 20px;
}

您可以使用以下命令將style.less 編譯為style.css

lessc style.less style.css

執行上述命令;它將自動建立style.css 檔案,其中包含以下程式碼 −

style.css

p {
   color: #A0A0A0;
   font-family: "Comic Sans MS";
   font-size: 20px;
}

輸出

請按照以下步驟檢視上述程式碼的工作原理 −

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

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

LESS Import Options Reference

reference 具有extend 方法,該方法會在您引用@import 語句的地方引入一個新的選擇器,並將其標記為未引用。有關更多資訊,請點選此處

less_import_options.htm
廣告

© . All rights reserved.