引用和参考的less文档
效果(还是挺好看的:-D ):
我的实例代码:
@primary-color: #3D7FFF;
.average(@x, @y) {
@result: ((@x + @y)/2);
}
.withOutAverage(@x, @y) {
@result: (@x + @y);
}
.contrast-1 {
height: 100px;
width: 100px;
background-color: @primary-color;
}
.TestView{
height: 100px;
width: 100px;
background-color: .average(@primary-color, #3dffcd)[];
}
.contrast-2 {
height: 100px;
width: 100px;
background-color: #3dffcd;
}
.contrast-3 {
height: 100px;
width: 100px;
background-color: .withOutAverage(@primary-color, #3dffcd)[];;
}
<View className={css["contrast-1"]}>withOutAverage</View>
<View className={css["TestView"]}>TestView</View>
<View className={css["contrast-2"]}>#3dffcd</View>
<View className={css["contrast-3"]}>withOutAverage</View>
官方样例是用来计算px的,
这里也转一下吧:
Example:
.average(@x, @y) {
@result: ((@x + @y) / 2);
}
div {
// call a mixin and look up its "@result" value
padding: .average(16px, 50px)[@result];
}
Results in:
div {
padding: 33px;
}