问题
.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?
回答1:
Because $x
is equal to the full selector (.a, .b
), never to .a
or .b
.
What you're trying to achieve would be:
.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;
}
来源:https://stackoverflow.com/questions/26523745/scss-sass-statement-referencing-to-parent-not-work