个性化阅读
专注于IT技术分析

LESS多重和父选择器

点击下载

在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>srcmini: 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

LESS多重和父选择器

这将编译” simple.less”文件。将生成一个名为” simple.css”的CSS文件。

例如:

LESS多重和父选择器

生成的CSS” simple.css”具有以下代码:

.select + .select {
  color: pink;
}
.select .select {
  color: blue;
}
.select.select {
  color: red;
}
.select, .select_class1 {
  color: green;
}

输出

LESS多重和父选择器
赞(0)
未经允许不得转载:srcmini » LESS多重和父选择器

评论 抢沙发

评论前必须登录!