快速入门
概览
变量(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!)
作用域
CSS Guards - Less入门文档 - 笔下光年
网站首页
CSS Guards
"if" 的周围选择器 发布于 v1.5.0 与 Mixin Guards 一样,guards 也可以应用于 css 选择器,这是一种语法糖,用于声明 mixin 并立即调用它。 例如,在 1.5.0 之前,您必须这样做: ```less .my-optional-style() when (@my-option = true) { button { color: white; } } .my-optional-style(); ``` 现在,您可以直接将保护装置应用到样式中。 ```less button when (@my-option = true) { color: white; } ``` 您还可以通过将其与 `&` 功能相结合来实现 `if` 类型语句,从而对多个保护进行分组。 ```less & when (@my-option = true) { button { color: white; } a { color: blue; } } ``` 请注意,您也可以通过使用实际的 `if()` 函数和变量调用来实现类似的模式。如 ```less @dr: if(@my-option = true, { button { color: white; } a { color: blue; } }); @dr(); ```
上一篇:
Mixins
下一篇:
分离规则集