Less匯入選項inline關鍵詞


@import (inline)將您的 CSS 複製到輸出的 CSS檔案而不處理它。這時候,CSS檔案不能相容Less是非常有用的。雖然 Less 支援大多數標準CSS,在某些地方不支援注釋和不修改的CSS。儘管@import (inline) 不處理CSS,這將確保你的所有 CSS 在一個檔案中。

範例

下面的例子演示了LESS檔案中使用 inline關鍵字:
<html>
<head>
  <link rel="stylesheet" href="style.css" type="text/css" />
  <title>Import Option Inline</title>
</head>
<body>
<h1>Welcome to Yiibai Yiibai</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) "/";
p {
  color:red;
}
這將在從下面程式碼的路徑 / 匯入所述 import_inline.css 檔案到 style.less:

import_inline.css

.style {
    "Comic Sans MS";
    font-size: 20px;
}
你可以編譯 style.less 使用下面的命令到 style.css 檔案:
lessc style.less style.css
接著執行上面的命令,它會自動建立 style.css 檔案,下面的程式碼:

style.css

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

輸出結果

讓我們來執行以下步驟,看看上面的程式碼工作:
  • 儲存上面的HTML程式碼在 import_options_inline.html 檔案。
  • 在瀏覽器中開啟該HTML檔案,得到如下輸出顯示。