LESS 混合作用域
LESS 混合作用域
由变量组成的混合对于调用者是可见和可调用的。但是有一个例外,如果调用者包含一个具有相同名称的变量,那么该变量不会复制到调用者的范围。只有调用者范围内的变量受到保护,继承的变量被重写。
例子
<html> <head> <link rel = "stylesheet" href = "style.css" type = "text/css" /> <title>Mixins Scope</title> </head> <body> <div class = "myclass"> <h2>Welcome to Tutorialspoint</h2> <p>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p> </div> </body> </html>
接下来创建style.less文件.
/*style.less*/
.mixin() {
@bgcolor: #C0C0C0;
}
.myclass{
.mixin();
background-color: @bgcolor;
}使用下面命令编译less文件
lessc style.less style.css
得到css
/*style.css*/
.myclass {
background-color: #C0C0C0;
}输出
执行下面步骤:
保存上述代码到less_mixin_as_function_scope.html文件.
在浏览器中执行以查看效果.
