Less MP选择器
Less MP选择器
在Less中,&运算符用于重复引用父选择器而不使用其名称。因此,multiple&parent选择器指定在选择器&运算符内可以多次使用。
多个&示例
让我们以一个示例来演示多个&父选择器的用法。
创建具有以下数据的名为"simple.html"的HTML文件。
strong> HTML文件: simple.html
<!DOCTYPE html>
<html>
<head>
<title>Multiple & Example</title>
<link rel="stylesheet" href="simple.css" type="text/css" />
</head>
<body>
<h2>lidihuo: A solution of all technology.</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>
现在创建一个名为"simple.less"的文件。它类似于CSS文件。唯一的区别是它以" .less"扩展名保存。
LESS文件: simple.less
.select + .select {
color: pink;
}
.select .select {
color: blue;
}
.select.select {
color: red;
}
.select,
.select_class1 {
color: green;
}
将文件"simple.html"和"simple.less"都放入Node.js的根文件夹中
现在,执行以下代码: lessc simple.less simple。 css
这将编译"simple.less"文件。将生成一个名为" simple.css"的CSS文件。
例如:
生成的CSS" simple.css"具有以下代码:
.select + .select {
color: pink;
}
.select .select {
color: blue;
}
.select.select {
color: red;
}
.select,
.select_class1 {
color: green;
}
输出:
