为什么浏览器要为 CSS 属性创建供应商前缀?
也许这是一个显而易见的答案,但是
到底为什么浏览器会决定为border-radius
等创建自己的供应商前缀?
我的意思是:为什么我必须输入:
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
是因为每个平台都认为“我们很酷,我们会想出一种更好的圆角方法?”一行输入三行似乎完全且莫名其妙地多余。
Maybe it's an obvious answer, but
Why on earth would browsers decide to create their own vendor prefixes for border-radius
and the like?
I mean: Why do I have to type:
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
Is it because each platform thought "We're cool, we'll come up with a better way to do rounded corners?" It seems totally and inexplicably redundant to type three lines for one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为这些功能是在规范达到最终发布阶段之前由供应商实现的。
供应商前缀确保不与不断变化的功能等发生冲突。
源的页面。
It's because the features were implemented by vendors before the specification reached its final release stage.
The vendor prefixes ensure that there are no clashes with changing functionality etc.
Source.
由于这篇文章很旧,值得一提的是,现在大多数供应商确实明白这些前缀只是创建不必要的重复代码,以及您需要指定 3 种不同的 CSS 规则才能在所有情况下获得一种效果的情况浏览器是一个不需要的浏览器。
正如 本词汇表中提到的,Mozilla 5 月 3 日对供应商前缀的看法, 2016年,
例如,就在几年前,要在盒子上设置圆角,您必须编写:
但现在浏览器已经完全支持此功能,您实际上只需要标准化版本:
As this post old, it's important to mention that now most vendors do understand that these prefix are just creating unnecessary duplicate code and the situation where you need to specify 3 different CSS rules to get one effect working in all browser is an unwanted one.
As mentioned in this glossary about Mozilla's view on vendor prefixes on May 3, 2016,
For example, just a few years ago, to set a rounded corner on a box you had to write:
But now that browsers have come to fully support this feature, you really only need the standardized version: