【问题标题】:sass include mixin as a parametersass 包含 mixin 作为参数
【发布时间】:2014-01-19 04:32:35
【问题描述】:

我想对 sass mixins 进行参数化,使其扩展为其他 mixin 作为参数传递的扩展名。

@mixin c(){color:red}

@mixin view($param){*{@include #{$param}}}

div{@include view}

我尝试过的第二行及其变体不起作用,我还没有找到任何方法将变量传递到@include 子句中

【问题讨论】:

标签: sass


【解决方案1】:

你可以尝试在mixin里面添加一些条件:

@mixin test1(){
  color: red;
}

@mixin test2(){
  color: blue;
}

@mixin view($param){
  .test{
    @if $param == 'test1'{
      @include test1();
    }

    @if $param == 'test2'{
      @include test2();
    }
  }
}

div{
  @include view(test1);
}

【讨论】:

    猜你喜欢
    • 2014-10-01
    • 2012-04-23
    • 2023-03-20
    • 2013-01-05
    • 2013-08-29
    • 2020-06-13
    • 1970-01-01
    • 2015-05-07
    • 2012-04-26
    相关资源
    最近更新 更多