LESS - 匯入選項 Less 關鍵字



描述

@import (less) 將檔案作為 LESS 檔案匯入,無論副檔名是什麼。此功能在1.4.0 版本中釋出。

示例

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

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>Import Options Less</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 (less) "https://tutorialspoint.tw/less/less.txt";
.para_1 {
   color: red;
   .style;
}

.para_2 {
   color: blue;
}

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

less.txt

.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;
}

.para_1 {
   color: red;
   font-family: "Comic Sans MS";
   font-size: 20px;
}

.para_2 {
   color: blue;
}

輸出

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

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

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

LESS Import Options Less
less_import_options.htm
廣告

© . All rights reserved.