LESS 混合和返回值
LESS 混合和返回值
混合类似于函数,在混合定义的变量将作为返回值运行。
例子
<html> <head> <link rel = "stylesheet" href = "style.css" type = "text/css" /> <title>Mixins & return values</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*/
.padding(@x, @y) {
@padding: ((@x + @y) / 2);
}
.myclass{
.padding(80px, 120px); // call to the mixin
padding-left: @padding; // returns the value
}使用下面命令编译less文件
lessc style.less style.css
得到css文件
/*style.css*/
.myclass {
padding-left: 100px;
}输出
执行下面步骤:
保存上述代码到less_mixin_as_function_return_values.html文件.
在浏览器中执行以查看效果.
