LESS 导入选项参考关键字

2018-01-10 17:29 更新

描述

@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 Tutorialspoint</h1>
<p>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
</body>
</html>


接下来,创建文件 style.less

风格

@import (reference) "//www.w3cschool.cn/statics/demosource/import_reference.less";
p {
    .style1;
}


import_reference.less文件将从//www.w3cschool.cn/statics/demosource/import_reference.less导入到style.less。以下代码:

import_reference.less

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


您可以使用以下命令将 style.less 编译为 style.css :

lessc style.less style.css



接下来执行上面的命令,它将用下面的代码自动创建 style.css 文件:

style.css

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


输出

让我们执行以下步骤,看看上面的代码如何工作:

  • import_options_reference.html 文件中保存上面的html代码。

  • 在浏览器中打开此HTML文件,将显示如下输出。


输出


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号