在基于供应商的CSS3与标准CSS3语法中订购 [英] Ordering in vendor based CSS3 Vs Standard CSS3 syntax

查看:126
本文介绍了在基于供应商的CSS3与标准CSS3语法中订购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了实现跨浏览器兼容性,我们倾向于使用供应商特定的扩展和标准的CSS3语法。我知道CSS3仍在草稿中,但我们已经开始使用它了。但问题是,它们发生的地方的顺序是否非常重要?

In order to achieve cross-browser compatibility, we tend to use both vendor specific extensions and standard CSS3 syntax. I know CSS3 is still in draft, but we have already started using it. But the question is, does the order of where they occur matter very much?

例如,让我们看看这里

-moz-border-radius: 10px;
border-radius: 10px;

这适用于浏览器特定 border-radius

同样,切换顺序

border-radius: 10px;
-moz-border-radius: 10px;

现在,首先尝试标准语法,然后返回基于浏览器的扩展。

Now, this tries standard syntax first and then falls back to browser based extension.

它有任何差异造成的排序?

It there any difference caused by the ordering? May be in terms of performance or else.

推荐答案


现在,首先尝试标准语法,然后

Now, this tries standard syntax first and then falls back to browser based extension.

这可能是一个误导性的陈述。符合规范的浏览器将首先尝试标准的无前缀属性, 如果 除了支持标准之外,还将应用该前缀。这通常导致标准声明被前缀声明覆盖,并且浏览器可能会非常标准地实现该属性,从而破坏了首先具有标准属性的目的。

This may be a misleading statement. A compliant browser will try the standard unprefixed property first, but if it also supports the prefixed property in addition to the standard, then it will apply that prefix as well. This usually results in the standard declaration being overridden by the prefixed declaration and a browser's potentially non-standard implementation of that property, defeating the purpose of having the standard property there in the first place.

最后声明无前缀属性的原因是因为这是属性在规则中级联的方式:浏览器将总是使用最后一个适用的属性。前缀和非前缀版本的属性被视为与级联相同的属性,因此您希望浏览器在应用该属性时尽最大努力遵守标准。 1

The reason why you should declare the unprefixed property last is because that's how properties cascade in a rule: a browser will always use the last applicable one. Prefixed and unprefixed versions of a property are treated as the same property with respect to the cascade, so you want a browser to do its best to adhere to the standards when applying that property.1

如果浏览器实现了一个前缀而不是标准,那就没问题,但如果它实现了两者,你想确保它使用标准。您可以通过最后声明标准属性来实现此目的。

If a browser implements a prefix but not the standard, that's fine, but if it implements both, you want to ensure it uses the standard instead. You do this by declaring the standard property last.

1 我知道这不是规范,因为就规范,供应商扩展是非标准的,所以他们的实现不能描述。尽管规范中介绍了供应商前缀的语法,但实施

1 As far as I'm aware this is not dictated by the spec, because as far as the spec is concerned vendor extensions are non-standard and so their implementation cannot be described. Although the syntax of vendor prefixes is described in the spec, implementations are left entirely up to the discretion of vendors.

然而,大多数浏览器开发者在实现前缀的a的时候,标准化的属性或规则,始终将前缀和后缀版本作为彼此的别名。

这篇关于在基于供应商的CSS3与标准CSS3语法中订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆