快速入门
概览
变量(Variables)
混合(Mixins)
嵌套(Nesting)
运算(Operations)
转义(Escaping)
函数(Functions)
命名空间和访问符
映射(Maps)
作用域(Scope)
注释(Comments)
导入(Importing)
Less.js 用法
命令行用法
浏览器使用
Less.js选项
预装插件
程序化使用
API
Contributing to Less.js
Less 函数手册
逻辑函数
字符串函数
列表函数
数学函数
类型函数
其他功能
颜色定义函数
颜色通道函数
颜色操作函数
颜色混合函数
进阶指南
合并
父选择器
扩展
变量
Mixins
CSS Guards
Detached Rulesets
@import At-Rules
@plugin At-Rules
Maps (NEW!)
Less入门文档
网站首页
CSS Guards
"if"'s around selectors Released v1.5.0 Like Mixin Guards, guards can also be applied to css selectors, which is syntactic sugar for declaring the mixin and then calling it immediately. For instance, before 1.5.0 you would have had to do this: ```less .my-optional-style() when (@my-option = true) { button { color: white; } } .my-optional-style(); ``` Now, you can apply the guard directly to a style. ```less button when (@my-option = true) { color: white; } ``` You can also achieve an if type statement by combining this with the & feature, allowing you to group multiple guards. ```less & when (@my-option = true) { button { color: white; } a { color: blue; } } ``` Note that you can also achieve a similar pattern by using the actual if() function and a variable call. As in: ```less @dr: if(@my-option = true, { button { color: white; } a { color: blue; } }); @dr(); ```
上一篇:
Mixins
下一篇:
Detached Rulesets