对于初学者,(在撰写此答案时)没有使用selector&的 sass 语法。如果你打算做这样的事情,你需要在选择器和 & 号之间留一个空格。例如:
.item {
.helper & {
}
}
// compiles to:
.helper .item {
}
使用&符号的另一种方式可能是您(错误地)寻找的:
.item {
&.helper {
}
}
// compiles to:
.item.helper {
}
这允许您使用其他类、ID、伪选择器等来扩展选择器。不幸的是,对于您的情况,理论上这会编译成类似 .itema 的东西,这显然是行不通的。
您可能只是想重新考虑如何编写 CSS。有可以使用的父元素吗?
<div class="item">
<p>text</p>
<p>text</p>
<a href="#">a link</a>
</div>
这样,您可以轻松地以下列方式编写您的 SASS:
.item {
p {
// paragraph styles here
}
a {
// anchor styles here
}
}
(旁注:你应该看看你的 html。你混合了单引号和双引号,并将 href 属性放在 p 标签上。)