2013-11-26 25 views
1

我有2个类风格的标题。然后,我需要创建一个mixin来定制背景模式,具体取决于显示哪个头。调用类变量insida一个混合 - Sass

是否可以在我的mixin中使用$ has-dept变量?

//header 1 
    .dt-style-user-bar-without-departments { 
      @extend .dt-style-user-bar; 
      $has-dept: false; 
      /... 
    } 

    //header 2 
    .dt-style-user-bar-with-departments { 
      @extend .dt-style-user-bar; 
      $has-dept: false; 
      //... 
    } 

    //intending to get $has-dept var to give the proper background color 
    @mixin set-reveal-bg-color(){ 
      @extend $has-dept; 
      @if $has-dept { 
      background: green !important; 
      } 
      @else { 
      background: blue !important; 
      } 
    } 

    //prints the background color in the modal overlay class 
    .reveal-modal-bg{ 
     @include set-reveal-bg-color() 
    } 

*输出:错误SCSS/app.scss(线SCSS/_dt_style.scss 471:未定义的变量: “$有-部门”。)*

+0

不能使用'@ extend'指令变量,它仅适用于选择器。来自[SASS reference](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#extend):'@ extend'指令通过告诉Sass一个**选择器**应该继承这些样式来避免这些问题另一个**选择器** [...] –

+0

你能展示你想在CSS中实现什么吗? –

回答