Less-条件判断

less中可以通过when给混合添加执行限定条件, 只有条件满足(为真)才会执行混合的代码
when表达式中可以使用比较运算符(> < >= <= =)、逻辑运算符、或检查函数来进条件判断

  • (),()相当于JS中的||
/* 当下边 div 中 .size 传入的第一个参数是100px或者第二个参数是100px才会执行*/
.size(@width,@height) when (@width = 100px),(@height = 100px){
  width: @width;
  height: @height;
}

div{
  .size(100px,100px);
  background: red;
}
  • ()and()相当于JS中的&&
/* 当下边 div 中 .size 传入的第一个参数是100px并且第二个参数是100px才会执行*/
.size(@width,@height) when (@width = 100px) and (@height = 100px){
  width: @width;
  height: @height;
}

div{
  .size(100px,100px);
  background: red;
}

你可能感兴趣的:(css预处理器,web前端开发)