SCSS / Sass - Statement referencing to parent not work

╄→гoц情女王★ 提交于 2019-12-12 03:18:13

问题


.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!