LiybSunshine 2016-07-26
在LESS中你可以使用"guarded mixin"来表达基本的逻辑:
.lightswitch(@colour) when (lightness(@colour) > 40%) {
color: @colour;
background-color: #000;
.box-shadow(0 3px 4px #ddd);
}
.lightswitch(@colour) when (lightness(@colour) < 41%) {
color: @colour;
background-color: #fff;
.box-shadow(0 1px 1px rgba(0,0,0,0.3));
}等价于SASS中的:
@mixin lightswitch($colour) {
color: $colour;
@if(lightness($colour) > 40%) {
background-color: #000;
@include box-shadow(0 3px 4px #ddd);
}
@if(lightness($colour) <= 40%) {
background-color: #fff;
@include box-shadow(0 1px 1px rgba(#000,0.3));
}
}在LESS中你可以使用数字实现循环
.looper (@i) when (@i > 0) {
.image-class-@{i} {
background: url("../img/@{i}.png") no-repeat;
}
.looper(@i - 1);
}
.looper(0);
.looper(3);输出:
.image-class-3 {
background: url("../img/10.png") no-repeat;
}
.image-class-2 {
background: url("../img/9.png") no-repeat;
}
.image-class-1 {
background: url("../img/8.png") no-repeat;
}在Sass中你可以枚举任何类型的数据,这个可能更有用
@each $beer in stout, pilsner, lager {
.#{$beer}-background {
background: url("../img/beers/#{$beer}.png") no-repeat;
}
}输出
.stout-background {
background: url("../img/beers/stout.png") no-repeat;
}
.pilsner-background {
background: url("../img/beers/pilsner.png") no-repeat;
}
.lager-background {
background: url("../img/beers/porter.png") no-repeat;
}在Sass中,你可以创建你顺手的字定义函数,像这样:
$em-base: 16px !default;
@function emCalc($pxWidth) {
@return $pxWidth / $em-base * 1em;
}LESS中:
@em-base: 16px;
.emCalc(@pxWidth) {
//Ah. 没办法了...
}切换到另一个工具所产生的不便和额外的时间消耗;
安装SASS请参考SASS官方网站: http://sass-lang.com/install