简体   繁体   English

CSS前缀关键帧是否可堆叠?

[英]Are CSS prefixed keyframes stackable?

Are CSS prefixed keyframes stackable as long as they don't include any prefixed specific attributes in them? CSS前缀关键帧是否可以堆叠,只要它们不包含任何前缀的特定属性?

Common 共同

@-webkit-keyframes myAnimation{
   to{ opacity:0; }
}
@-moz-keyframes myAnimation{
   to{ opacity:0; }
}
@keyframes myAnimation{
   to{ opacity:0; }
}

Stacked 叠放

@-webkit-keyframes myAnimation, @-moz-keyframes myAnimation, @keyframes myAnimation{
   to{ opacity:0; }
}

Not natively in CSS but you can accomplish this by using a CSS preprocessor, for example LESS which supports the concept of "mixins" to remove some duplication. 在CSS中本身不是,但你可以通过使用CSS预处理器来实现这一点,例如LESS支持“mixins”的概念来删除一些重复。

More info can be found here, specifically the example from the article: 可在此处找到更多信息,特别是文章中的示例:

 @-webkit-keyframes myAnimation {.mixi-frames;}
 @-moz-keyframes myAnimation {.mixi-frames;}

.mixi-frames () {
opacity:0;
}

It wouldn't work unfortunately. 不幸的是,它不会起作用。 If you group selectors, all of them have to be valid in order for any of them to be. 如果您对选择器进行分组,则所有这些选择器都必须有效,以便它们中的任何一个都可以。

For instance, if you used your stacked example... 例如,如果您使用了堆叠的示例...

@-webkit-keyframes myAnimation, @-moz-keyframes myAnimation, @keyframes myAnimation{
   to{ opacity:0; }
}

... on Firefox, it would read the webkit prefixed selector as invalid, which would make the rest of it, including the -moz- prefixed selector, also invalid. ...在Firefox上,它会将webkit前缀选择器视为无效,这将使其余部分(包括-moz-前缀选择器)也无效。

Travis' preprocessor workaround in the other answer is probably the best way to write it cleanly as you'd like. 特拉维斯在另一个答案中的预处理器解决方案可能是你想要干净利落地编写它的最好方法。

EDIT: This is misinformed, these can never be grouped as they are at-rules, not selectors. 编辑:这是错误的,这些永远不会被分组,因为它们是规则,而不是选择器。 Same obviously goes for media queries (@media), @font-face, etc. Check out Boltclock's comment below. 媒体查询(@media),@ font-face等显然也是如此。请查看下面的Boltclock评论。

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

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