简体   繁体   English

为什么@keyframes中的占位符选择器有效的.scss?

[英]Why are placeholder selectors inside @keyframes valid .scss?

I've been using parameterless mixins for pure CSS animations so that my classes and my keyframes don't contain a bunch of repetitive styles, something similar to the following: 我一直在为纯CSS动画使用无参数混合,这样我的类和关键帧就不会包含一堆重复的样式,类似于以下内容:

//css classes excluded for brevity, compile as expected

@mixin btn() {
    color: black;
}

@mixin btn-hover() {
    color: white;
}

@keyframes hover {
    from {
        @include btn();
    }
    to {
        @include btn-hover();
    }
}

Recently I converted those mixins to placeholder selectors like so: 最近,我将这些mixin转换为占位符选择器,如下所示:

//css classes excluded for brevity, compile as expected

%btn {
    color: black;
}

%btn-hover {
    color: white;
}

@keyframes hover {
    from {
        extend %btn;
    }
    to {
        extend %btn-hover;
    }
}

That didn't work, and in retrospect it's perfectly clear why not. 那是行不通的,回想起来很清楚为什么不这样做。 What confuses me is why this compiles in the first place. 令我感到困惑的是为什么它会首先编译。 The resulting CSS is valid @keyframes block that's completely empty: 生成的CSS是有效的@keyframes块,该块完全为空:

@keyframes hover {
}

Assuming my understanding of how the extend concept works in Sass is correct and complete, using placeholder selectors in this manner makes no sense. 假设我对扩展概念在Sass中的工作方式的理解是正确和完整的,以这种方式使用占位符选择器没有任何意义。 Why is this valid syntax to begin with? 为什么以这种有效的语法开头? Why don't I get a compile error? 为什么我没有编译错误?

It isn't considered valid and it should raise an error. 它被认为无效,应该引发错误。

Error from Sass 3.3: Sass 3.3错误:

You may not @extend an outer selector from within @keyframes.
You may only @extend selectors within the same directive.
From "@extend %btn" on line 11.

Error from Sass 3.4: Sass 3.4错误:

Extend directives may only be used within rules.

If you are using Sass 3.2 or older, you should upgrade. 如果您使用的是Sass 3.2或更早版本,则应升级。 If you're using LibSass, there's not much you can do about it other than report the issue on their bug tracker if it isn't already there. 如果您使用的是LibSass,那么除了在Bug跟踪器上报告该问题(如果尚未存在)之外,您无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM