示例
下面的例子演示了使用导入 LESS 文件:
Less ImportingExample using Importing
LESS enables customizable, manageable and reusable style sheet for web site.
It allows reusing CSS code and writing LESS code with same semantics.
LESS supports creating cleaner, cross-browser friendly CSS faster and easier.
接下来,创建文件 myfile.less。
myfile.less
.myclass{
color: #FF8000;
}
.myclass1{
color: #5882FA;
}
接下来,创建文件 style.less。
style.less
@import "http://www.yiibai.com/less/myfile.less";
.myclass2
{
color: #FF0000;
}
你可以编译 style.less 文件使用以下命令来生成 style.css 文件:
lessc style.less style.css
接着执行上面的命令,它会自动创建 style.css文件,下面的代码:
style.css
.myclass {
color: #FF8000;
}
.myclass1 {
color: #5882FA;
}
.myclass2 {
color: #FF0000;
}
输出
让我们来执行以下步骤,看看上面的代码工作:
保存上面的 html 代码到 importing.html 文件。
在浏览器中打开该HTML文件,得到如下输出显示。