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 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 (reference) "h/";
p {
    .style1;
}
這將在從下面碼的路徑 h/ 匯入所述 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檔案,得到如下輸出顯示。