在 Sass 中,如何引用父选择器并排除任何祖父母? [英] In Sass, How do you reference the parent selector and exclude any grandparent?
本文介绍了在 Sass 中,如何引用父选择器并排除任何祖父母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 sass 代码:
I have the following sass code:
.class{
label{
color:#fff;
.disabled &{color:#333; }
}
}
哪个输出
.disabled .class label
有没有办法输出父选择器而不包含任何祖父选择器?像这样:
Is there a way to output the parent selector without any grandparent selectors being included? Like so:
.disabled label
推荐答案
我知道在 SASS 中使用父引用时无法从祖先选择器中挑选和选择.但是,对于您的代码,稍加重组即可获得相同的结果:
There's no way I know of in SASS to pick and choose from ancestor selectors when using a parent reference. With your code, though, a little reorganization can get you the same result:
label {
.class & {
color: #fff;
}
.disabled & {
color:#333;
}
}
编译为:
.class label {
color: #fff; }
.disabled label {
color: #333; }
这篇关于在 Sass 中,如何引用父选择器并排除任何祖父母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文