快速入门
概览
变量(Variables)
混入(Mixins)
嵌套(Nesting)
运算(Operations)
转义(Escaping)
函数(Functions)
命名空间和访问符
映射(Maps)
作用域(Scope)
注释(Comments)
导入(Importing)
使用 Less.js
命令行用法
浏览器使用
Less.js选项
预加载插件
程序化使用
API
为 Less.js 做贡献
Less 函数手册
逻辑函数
字符串函数
列表函数
数学函数
类型函数
杂项函数
颜色定义函数
颜色通道函数
颜色操作函数
颜色混合函数
进阶指南
变量
父选择器
继承
合并
Mixins
CSS Guards
分离规则集
@import At-Rules
@plugin At-Rules
Maps (NEW!)
作用域
逻辑函数 - Less入门文档 - 笔下光年
网站首页
逻辑函数
### if 根据条件返回两个值之一。 参数: - `condition`: 布尔表达式 - `value1`: 如果 `condition` 为真,则返回该值。 - `value2`: 如果 `condition` 不为真,则返回该值。 发布于:v3.0.0 更新于:v3.6.0 示例: ```less @some: foo; div { margin: if((2 > 1), 0, 3px); color: if((iscolor(@some)), @some, black); } ``` 结果: ```css div { margin: 0; color: black; } ``` **注意:**`conditional` 参数支持的布尔表达式与 [守卫声明](http://www.bixiaguangnian.com/manual/less/1129.html#h3-mixin-guards "守卫声明") 相同。 ```less if(not (true), foo, bar); if((true) and (2 > 1), foo, bar); if((false) or (isstring("boo!")), foo, bar); ``` **注意:**在 Less 3.6 之前,条件需要一组括号。 ```less if(2 > 1, blue, green); // Causes an error in 3.0-3.5.3 if((2 > 1), blue, green); // Ok 3.0+ ``` ### boolean 评估为 `true` 或 `false` 您可以在 `guard` 或 `if()` 中 "存储" 布尔测试,以便以后进行评估。 参数: - `condition`: 布尔表达式 发布于:v3.0.0 更新于:v3.6.0 示例: ```less @bg: black; @bg-light: boolean(luma(@bg) > 50%); div { background: @bg; color: if(@bg-light, black, white); } ``` 结果: ```css div { background: black; color: white; } ```
上一篇:
Less 函数手册
下一篇:
字符串函数