- 语言特性
- 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 - 多重 &
描述
通过使用&运算符,可以重复引用父选择器而无需使用其名称。在选择器内,&可以多次使用。
示例
以下示例演示了在 LESS 文件中使用多个 & 的方法:
<html>
<head>
<title>Parent Selector</title>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>
<body>
<h2>Welcome to TutorialsPoint</h2>
<p class = "select">It is possible to reference the
parent selector by using &(ampersand) operator.</p>
<p class = "select_class1">It is possible to reference the
parent selector by using &(ampersand) operator</p>
</body>
</html>
接下来,创建 style.less 文件。
style.less
.select {
& + & {
color: #A9F5F2;
}
& & {
color: #D0FA58;
}
&& {
color: #81BEF7;
}
&, &_class1 {
color: #A4A4A4;
}
}
您可以使用以下命令将 style.less 文件编译为 style.css:
lessc style.less style.css
执行上述命令;它将自动创建 style.css 文件,其中包含以下代码:
style.css
.select + .select {
color: #A9F5F2;
}
.select .select {
color: #D0FA58;
}
.select.select {
color: #81BEF7;
}
.select,
.select_class1 {
color: #A4A4A4;
}
输出
按照以下步骤查看以上代码的工作原理:
将上述 html 代码保存在 parent_selector.htm 文件中。
在浏览器中打开此 HTML 文件,将显示以下输出。
&不仅代表最近的选择器,还代表所有父选择器。有关更多信息,点击此处。
less_parent_selectors.htm
广告