为什么 Chrome、FF、Opera 的 CSS 属性有不同的名称?
我想要一个名为“shadow”的 div 下面的阴影:
#shadow { box-shadow: 1px 1px 1px #000 };
完成了吗?
一点也不。它仅适用于一种浏览器。猜猜是哪一个。
对于 FF/Chrome,我必须添加不太直观的内容:
-moz-box-shadow: 1px 1px 1px #000;
-webkit-box-shadow: 1px 1px 1px #000;
现在一切都很好。此方案适用于许多 CSS 属性。为什么?
幸运的是,没有 -webkit-border、moz-font 或 -ie-backgroundcolor。
附言。是的,只字不提 IE。称其为浏览器就像将轮椅与摩德纳汽车进行比较一样。
PS 2. 为什么我的帖子下面的 Google Chrome 标签旁边有一个徽标?或者为什么没有 Opera & 的徽标? FF?
I want a shadow below div called "shadow":
#shadow { box-shadow: 1px 1px 1px #000 };
Done?
Not at all. It works just in one browser. Guess which one.
For FF/Chrome I have to add not too intuitive:
-moz-box-shadow: 1px 1px 1px #000;
-webkit-box-shadow: 1px 1px 1px #000;
And now everything is ok. This scheme applies to MANY CSS properties. Why?
Luckily there's no -webkit-border, moz-font or -ie-backgroundcolor.
PS. Yes, not a single word about IE. Calling THIS a browser is like comparing wheelchair to Modena cars.
PS 2. Why there is a logo next to Google Chrome tag below my post? Or why there are no logos for Opera & FF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
发生这种情况是因为浏览器不希望彼此发生冲突。除此之外,目前还没有真正的 box-shadow 的“规范”,因此几个浏览器都有自己的实现。
来源:http://reference.sitepoint.com/css/vendorspecific
This happens because browsers do not want conflicts with each other. In addition to that, there isn't really a "spec" for box-shadow at the moment, so several browsers have their own implementation of it.
Source: http://reference.sitepoint.com/css/vendorspecific
这是浏览器在 CSS 规范获得完全批准之前发布功能的一种方式。
例如,看看 CSS3 渐变。 -moz- 与 -webkit- 完全不同。
这可能会引起兴趣:http://www.alistapart.com/articles/prefix-或-posthack/
注意:最好包含不带前缀的版本,以便在完全采用该属性时继续站点功能。
It's a way for browsers to release features before the CSS Spec is fully approved.
For instance, look at the CSS3 gradients. -moz- vs -webkit- are completely different.
This may be of interest: http://www.alistapart.com/articles/prefix-or-posthack/
NOTE: It's good practice to include the version without the prefixes, as to continue the sites function when the property is fully adopted.
基于未完成规范实现的属性具有供应商前缀。如果给定的供应商认为他们的实现尚未完成,即使规范已经完成,也会发生同样的情况。
Properties which are implemented based on unfinishes specs are given vendor prefix. Same thing if given vendor thinks their implementation is not finished, even though the spec is.
浏览器的功能超出了它们应该遵循的标准。它们让您可以在标准发布之前暂时访问这些功能,然后它们遵循发布的标准并提供与看起来时髦的“webkit...”格式的向后兼容性。
The abilities of the browsers are ahead of the standards they're supposed to follow. They give you access to the abilities in the interim until the standard is published, then they follow the published standard and provide back-compatibility with the funky-looking "webkit..." formats.
正如其他人已经回答的那样,这是因为他们正在实现规范尚未完成的功能,或者其实现尚未完成的功能。
这是故意行为; CSS 规范指定在这种情况下他们应该这样做。制定此规则的原因如下:
例如:
-moz-border-radius
的早期版本与-webkit-border-radius
的工作方式完全不同;它们之间存在显着的语法差异,因此如果它们都只是border-radius
,您将无法同时支持它们。如果您确实使用带有供应商前缀的功能,请始终将该功能的无前缀版本放在最后,在其他版本之后。这样,最近升级为正确支持它的浏览器将选择正确的版本,而不是被过时的前缀版本覆盖。
这很重要:您应该清楚,使用带有供应商前缀的功能意味着您正在使用浏览器制造商和规范编写者认为尚未准备好的功能。你需要知道这一点。如果它有用,请不要让它阻止您使用某些东西,但请注意,下一个版本中的情况可能会发生变化。
As others have already answered, it is because they are implementing a feature for which the specifications are not yet complete, or a feature for which their implementation is not yet complete.
This is intentional behaviour; the CSS spec specifies that this is how they are supposed to do things in this case. The reasons for this rule are as follows:
For example: The early versions of
-moz-border-radius
worked quite differently to-webkit-border-radius
; there were significant syntax differences between them, so if they'd both been justborder-radius
, you wouldn't have been able to support them both.If you do use a feature with a vendor prefix, always put the non-prefixed version of the feature last, after the others. This way, a browser that has recently been upgraded to support it properly will pick up the correct version rather than it being overridden by the out-of-date prefixed version.
This is important: you should be clear that using a feature with vendor prefixes means that you're using a feature which the browser makers and specification writers do not believe is ready yet. You need to know this. Don't let it stop you using something if it's useful, but be aware that things may change with the next version.