SCSS变量为@extend类

Kev*_*wis 12 css sass

我的想法是,我想写和input[type=text],input[type="password"]input[type=submit].我会把@extend它们作为变量传递给混合物.

我的解析器抛出了这个错误;

Syntax error: Invalid CSS after "   @extend ": expected selector_sequence, was "$type;"
Run Code Online (Sandbox Code Playgroud)

这是我的代码;

%text {
    (text styling)
}

%password {
    @extend %text;
}

%submit {
    padding: .5em;
    background-color: $button-color;
    border: none;
    cursor: pointer;
    color: white;
    border: 1px solid darken($button-color, 20%);
    &:hover {
        @include transition;
        background-color: darken($button-color, 10%);
    }
}

@mixin input($type) {
    margin-bottom: 1.5em;
    margin-left: 0;
    outline: none;
    @extend $type;
}
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激

fca*_*ran 17

尝试使用变量插值

@extend #{$type};
Run Code Online (Sandbox Code Playgroud)

有关SASS参考的更多信息

  • 您不能扩展混合,只能扩展一个简单的选择器(类,ID,元素等)。另外,在将选择器作为参数传递给mixin时,您需要用引号引起来(例如,@include input('%foo')`)。 (2认同)