【问题标题】:& in SCSS extends issue& 在 SCSS 中扩展问题
【发布时间】:2017-08-06 15:01:31
【问题描述】:

在我的 scss 代码中,我试图制作如下占位符:

%input__label {
    color: red;
    &_content {
        color: blue;
    }
}

然后扩展它:

.input__label {
    @extend %input__label;
}

当我试图编译该代码时,只有 input__label 编译,但 input__label_content 没有:

.input__label {
   color: red;
}

(但例如使用伪元素 - &::after 一切正常) 为什么会这样?我正在使用 node v7.10.1 和 node-sass v4.5.3。

【问题讨论】:

    标签: css npm sass node-sass


    【解决方案1】:

    使用混合而不是扩展:

    @mixin input__label {
        color: red;
    
        &_content {
            color: blue;
        }
    }
    
    .input__label {
        @include input__label;
    }
    

    故意禁止通过 extends 执行此操作的功能: https://github.com/sass/sass/commit/face3172930b515ac2040e450d4db3ffe01c31b5

    【讨论】:

    • 哦,我不知道。非常感谢! =)
    猜你喜欢
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 2011-06-05
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多