LESS - 匯入選項 CSS 關鍵字



描述

@import (css) 關鍵字 將檔案作為普通 CSS 匯入,無論副檔名是什麼。此功能在1.4.0 版本中釋出。

示例

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

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

.para_2 {
   color: blue;
}

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

css.txt

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

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

lessc style.less style.css

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

style.css

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

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

.para_2 {
   color: blue;
}

輸出

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

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

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

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