LESS - 多關鍵詞匯入選項



描述

@import (multiple) 關鍵詞允許你匯入多個同名檔案。這與 once 的作用正好相反。此功能在 1.4.0 版本 中釋出。

示例

以下示例演示了在 LESS 檔案中使用 multiple 關鍵詞:

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

   <body>
      <h1>Welcome to Tutorialspoint</h1>
      <p class = "para_1">LESS is a CSS pre-processor that enables customizable, 
      manageable and reusable style sheet for web site.</p>
      <p class = "para_2">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 (multiple) "https://tutorialspoint.tw/less/multiple.less";
@import (multiple) "https://tutorialspoint.tw/less/multiple.less";
.para_1 {
   color: red;
}

.para_2 {
   color: blue;
}

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

multiple.less

.style {
   font-family: "Comic Sans MS";
   font-size: 20px;
}

你可以使用以下命令將 style.less 編譯成 style.css

lessc style.less style.css

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

style.css

.style {
   font-family: "Comic Sans MS";
   font-size: 20px;
}

.style {
   font-family: "Comic Sans MS";
   font-size: 20px;
}

.para_1 {
   color: red;
}

.para_2 {
   color: blue;
}

輸出

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

  • 將上述 html 程式碼儲存到 import_options_multiple.html 檔案中。

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

LESS Import Options Multiple
less_import_options.htm
廣告
© . All rights reserved.