- 語言特性
- 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 (inline) 語句會將你的 CSS 程式碼複製到輸出的 CSS 檔案中,而不會對其進行處理。這在 CSS 檔案不相容 LESS 時非常有用。雖然 LESS 支援大多數標準 CSS,但在某些地方不支援註釋,如果不修改 CSS,它將不支援所有已知的 CSS hacks。即使@import (inline)不會處理 CSS,它也能確保所有 CSS 程式碼都在一個檔案中。此功能在 1.5.0 版本中釋出。
示例
以下示例演示了在 LESS 檔案中使用reference關鍵字:
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
<title>Import Option Inline</title>
</head>
<body>
<h1>Welcome to Tutorialspoint</h1>
<p>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 (inline) "https://tutorialspoint.tw/less/import_inline.css";
p {
color:red;
}
以下程式碼將從路徑https://tutorialspoint.tw/less/import_inline.css使用以下程式碼將import_inline.css檔案匯入到style.less中:
import_inline.css
.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;
}
p {
color: red;
}
輸出
按照以下步驟檢視上述程式碼的工作原理:
將上述 html 程式碼儲存在import_options_inline.html檔案中。
在瀏覽器中開啟此 HTML 檔案,將顯示以下輸出。
如果您嘗試在style.less中的p標籤內使用.style類,它將丟擲一個未定義的錯誤。
less_import_options.htm
廣告