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

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值