less学习(七)—作为函数使用的Mixin

来源:互联网 发布:美女网络名字大全 编辑:程序博客网 时间:2024/06/10 11:14

All variables defined in a mixin are visible and can be used in caller's scope (unless the caller defines its own variable with the same name)(所有在混合里定义的变都是可见的并且可以在调用混合的css规则集里使用,除非这个调用混合的css有它自己的相同名字的变量)

.mixin() {  @width:  100%;  @height: 200px;}.caller {  .mixin();  width:  @width;  height: @height;}
输出为:

.caller {  width:  100%;  height: 200px;}
Thus variables defined in a mixin can act as its return values. This allows us to create a mixin that can be used almost like a function(因此,在混合里定义的变量能以它返回的值起作用。者就允许我们去创建一个类似函数的混合)

.average(@x, @y) {  @average: ((@x + @y) / 2);}div {  .average(16px, 50px); // "call" the mixin  padding: @average;    // use its "return" value}
输出为:

div {  padding: 33px;}