- 語言特性
- Less - 巢狀規則
- Less - 巢狀指令和冒泡
- Less - 操作
- Less - 轉義
- Less - 函式
- Less - 名稱空間和訪問器
- Less - 作用域
- Less - 註釋
- Less - 匯入
- Less - 變數
- Less - 擴充套件
- Less - 混合宏
- Less - 引數化混合宏
- Less - 混合宏作為函式
- Less - 將規則集傳遞給混合宏
- Less - 匯入指令
- Less - 匯入選項
- Less - 混合宏保護
- Less - CSS 保護
- Less - 迴圈
- Less - 合併
- Less - 父選擇器
- 函式
- Less - 雜項函式
- Less - 字串函式
- Less - 列表函式
- Less - 數學函式
- Less - 型別函式
- Less - 顏色定義函式
- Less - 顏色通道函式
- Less - 顏色操作
- Less - 顏色混合函式
- 用法
- Less - 命令列用法
- 在瀏覽器中使用 Less
- Less - 瀏覽器支援
- Less - 外掛
- Less - 程式化用法
- Less - 線上編譯器
- Less - GUI
- Less - 編輯器和外掛
- Less - 第三方編譯器
- Less - 框架
- Less 有用資源
- Less - 快速指南
- Less - 有用資源
- Less - 討論
LESS - 匯入選項 Once 關鍵字
描述
@import (once) 關鍵字確保檔案只匯入一次,並且任何後續的匯入語句都會被忽略。這是 @import 語句的預設行為。此功能在 1.4.0 版本中釋出。
示例
以下示例演示了在 LESS 檔案中使用 once 關鍵字的方法:
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
<title>Import Options Once</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 (once) "https://tutorialspoint.tw/less/once.less";
@import (once) "https://tutorialspoint.tw/less/once.less"; // this statement will be ignored
.para_1 {
color: red;
.style;
}
.para_2 {
color: blue;
}
以下程式碼將從 https://tutorialspoint.tw/less/once.less 路徑將 once.less 檔案匯入到 style.less 中:
once.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;
}
.para_1 {
color: red;
font-family: "Comic Sans MS";
font-size: 20px;
}
.para_2 {
color: blue;
}
輸出
請按照以下步驟檢視上述程式碼的工作原理:
將上述 html 程式碼儲存在 import_options_once.html 檔案中。
在瀏覽器中開啟此 HTML 檔案,將顯示以下輸出。
less_import_options.htm
廣告