- 语言特性
- LESS - 嵌套规则
- LESS - 嵌套指令和冒泡
- LESS - 运算
- LESS - 转义
- LESS - 函数
- LESS - 命名空间和访问器
- LESS - 作用域
- LESS - 注释
- LESS - 导入
- LESS - 变量
- LESS - 扩展
- LESS - 混合宏
- LESS - 参数化混合宏
- LESS - 混合宏作为函数
- LESS - 向混合宏传递规则集
- LESS - 导入指令
- LESS - 导入选项
- LESS - 混合宏保护
- LESS - CSS 保护
- LESS - 循环
- LESS - 合并
- LESS - 父选择器
- 函数
- LESS - 杂项函数
- LESS - 字符串函数
- LESS - 列表函数
- LESS - 数学函数
- LESS - 类型函数
- LESS - 颜色定义函数
- LESS - 颜色通道函数
- LESS - 颜色运算
- LESS - 颜色混合函数
- 用法
- LESS - 命令行用法
- 在浏览器中使用 LESS
- LESS - 浏览器支持
- LESS - 插件
- LESS - 程序化用法
- LESS - 在线编译器
- LESS - GUI
- LESS - 编辑器和插件
- LESS - 第三方编译器
- LESS - 框架
- LESS 有用资源
- LESS - 快速指南
- LESS - 有用资源
- LESS - 讨论
LESS - CSS 保护
描述
保护用于匹配表达式上的简单值或多个参数。它应用于 CSS 选择器。它是声明混合宏并立即调用的语法。为了成功实现if类型语句;将其与特性&结合使用,允许你组合多个保护。
示例
以下示例演示了在 LESS 文件中使用css保护:
css_guard.htm
<!doctype html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>
<body>
<div class = "cont">
<h2>Welcome to TutorialsPoint</h2>
</div>
<div class = "style">
<h3>The largest Tutorials Library on the web.</h3>
</div>
</body>
</html>
接下来,创建style.less文件。
style.less
@usedScope: global;
.mixin() {
@usedScope: mixin;
.cont when (@usedScope = global) {
background-color: red;
color: black;
}
.style when (@usedScope = mixin) {
background-color: blue;
color: white;
}
@usedScope: mixin;
}
.mixin();
您可以使用以下命令将style.less文件编译为style.css:
lessc style.less style.css
执行上述命令;它将自动创建包含以下代码的style.css文件:
style.css
.style {
background-color: blue;
color: white;
}
输出
按照以下步骤查看上述代码的工作原理:
将上述 html 代码保存到css_guard.htm文件中。
在浏览器中打开此 HTML 文件,将显示以下输出。
广告