【问题标题】:SCSS / Sass - Statement referencing to parent not workSCSS / Sass - 引用父级的语句不起作用
【发布时间】:2014-10-23 16:56:40
【问题描述】:
.a, .b
{
   color: red;

   $x: &;

   @if $x == '.b'
   {
     color: $x;
   }


}

http://sassmeister.com/gist/ad7fa7f3a431f3e2d4e0

不工作,为什么?你能帮我解决一些问题吗?

【问题讨论】:

    标签: if-statement sass compass-sass


    【解决方案1】:

    因为$x 等于完整选择器 (.a, .b),永远不会等于 .a.b

    你想要达到的目标是:

    .a, .b {
      color: red;
    
      &.b {
        color: blue;
      }
    }
    

    但它会生成这段代码(工作,但未优化):

    .a, .b {
      color: red;
    }
    .a.b, .b.b {
      color: blue;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 2017-09-15
      • 2021-05-27
      • 2021-01-31
      • 2012-11-19
      • 2019-11-19
      • 1970-01-01
      相关资源
      最近更新 更多