- 語言特性
- LESS - 巢狀規則
- LESS - 巢狀指令和冒泡
- LESS - 運算
- LESS - 轉義
- LESS - 函式
- LESS - 名稱空間和訪問器
- LESS - 作用域
- LESS - 註釋
- LESS - 匯入
- LESS - 變數
- LESS - 擴充套件
- LESS - Mixin
- LESS - 引數化Mixin
- LESS - Mixin作為函式
- LESS - 向Mixin傳遞規則集
- LESS - 匯入指令
- LESS - 匯入選項
- LESS - Mixin 保護
- LESS - CSS 保護
- LESS - 迴圈
- LESS - 合併
- LESS - 父選擇器
- 函式
- LESS - 雜項函式
- LESS - 字串函式
- LESS - 列表函式
- LESS - 數學函式
- LESS - 型別函式
- LESS - 顏色定義函式
- LESS - 顏色通道函式
- LESS - 顏色運算
- LESS - 顏色混合函式
- 用法
- LESS - 命令列用法
- 在瀏覽器中使用LESS
- LESS - 瀏覽器支援
- LESS - 外掛
- LESS - 程式化用法
- LESS - 線上編譯器
- LESS - 圖形使用者介面
- LESS - 編輯器和外掛
- LESS - 第三方編譯器
- LESS - 框架
- LESS 有用資源
- LESS - 快速指南
- LESS - 有用資源
- LESS - 討論
LESS - 匯入選項擴充套件
描述
當擴充套件選擇器時,新的選擇器會替換 `@import` 語句中的引用位置,只有新的選擇器被標記為 *未引用*。我們可以使用 `extend` 來避免這種冗餘,只引入特定目標樣式。
示例
下面的例子演示了在LESS檔案中使用 *extend* 方法:
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
<title>Import Options Extend</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 (reference) "https://tutorialspoint.tw/less/import_options_extend.less";
.para_1 {
&:extend(.style1);
background-color: #81F7F3;
}
.para_2 {
&:extend(.style1);
background-color: #F6E3CE;
}
下面的程式碼將從 https://tutorialspoint.tw/less/import_options_extend.less 路徑匯入 *import_options_extend.less* 檔案到 *style.less* 中:
import_options_extend.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
.para_1,
.para_2 {
color: #A0A0A0;
font-family: "Comic Sans MS";
font-size: 20px;
}
.para_1 {
background-color: #81F7F3;
}
.para_2 {
background-color: #F6E3CE;
}
輸出
按照以下步驟檢視上述程式碼的工作原理:
將上述HTML程式碼儲存到 **import_options_reference_extend.html** 檔案中。
在瀏覽器中開啟此HTML檔案,將顯示以下輸出。
less_import_options.htm
廣告