codecamp

LESS 导入选项参考关键字

描述

@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,免费阅读超1000+编程语言教程
取消
确定
目录

Less 基本教程

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }