Less 逻辑函数

if

条件返回两个值之一。

参数:

  • 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+

boolean

为真或假。

你可以 "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;
}
说说我的看法
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号