条件返回两个值之一。
参数:
condition: 布尔表达式
value1: 如果 condition 为真,则返回该值。
value2: 如果 condition 不为真,则返回该值。
发布于: v3.0.0
更新于: v3.6.0
示例:
@some: foo;
div {
margin: if((2 > 1), 0, 3px);
color: if((iscolor(@some)), @some, black);
}结果:
div {
margin: 0;
color: black;
}注意: conditional 参数支持的布尔表达式与守卫声明相同。
if(not (true), foo, bar);
if((true) and (2 > 1), foo, bar);
if((false) or (isstring("boo!")), foo, bar);注意:在 Less 3.6 之前,条件需要一组括号。
if(2 > 1, blue, green); // Causes an error in 3.0-3.5.3 if((2 > 1), blue, green); // Ok 3.6+
为真或假。
你可以 "store" 布尔测试以供以后在守卫中进行评估或 if()。
参数:
condition: 布尔表达式
发布于: v3.0.0
更新于: v3.6.0
示例:
@bg: black;
@bg-light: boolean(luma(@bg) > 50%);
div {
background: @bg;
color: if(@bg-light, black, white);
}结果:
div {
background: black;
color: white;
}