SCSS / Sass - 引用父项的语句不起作用 [英] SCSS / Sass - Statement referencing to parent not work
本文介绍了SCSS / Sass - 引用父项的语句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.a, .b
{
color: red;
$x: &;
@if $x == '.b'
{
color: $x;
}
}
http://sassmeister.com/gist/ad7fa7f3a431f3e2d4e0
不行,为什么?你可以帮我解决一些问题吗?
Not work, why? Could you help me someone with some fix?
推荐答案
因为 $ x
等于完整选择器( .a,.b
),永远不会 .a
或 .b
。
Because $x
is equal to the full selector (.a, .b
), never to .a
or .b
.
您要实现的目标是:
.a, .b {
color: red;
&.b {
color: blue;
}
}
但它会生成此代码(工作,但不是优化):
But it will generate this code (working, but not optimized):
.a, .b {
color: red;
}
.a.b, .b.b {
color: blue;
}
这篇关于SCSS / Sass - 引用父项的语句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文