有没有一种方法可以为CSS中的特定浏览器设置任何样式? [英] Is there a way to set any style for a specific browser in CSS?

查看:332
本文介绍了有没有一种方法可以为CSS中的特定浏览器设置任何样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果要在Webkit,Firefox和其他环境中设置拐角半径,可以使用以下CSS:

For example, if I want to set the corner radius in Webkit, Firefox and other than I can use the following CSS:

-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;

但是这些样式是硬编码的还是只是在浏览器中添加了前缀地址?

But are those styles hardcoded or is merely adding a prefix address that browser?

例如,如果我只想在Firefox中更改页边距,我可以像这样简单地添加前缀:

For example, if I want to change the margin only in Firefox could I simply add the prefix like so:

-moz-margin:-4px;
margin: 1px;

不错的提示:
如果可能的话,是否可以解决特定的版本或平台?例如,-moz-4.3-margin:-4px;不是我想要的,只是想知道.

NICE TO KNOW:
And if that's possible is it possible to address a specific version or platform? For example, -moz-4.3-margin:-4px; not that I'd want to, just wondering.

前缀方法在跨浏览器中是否有效?我想知道是因为Internet Explorer.

And does the prefix approach work cross browser? I'm wondering because Internet Explorer.

最后,margin:10px是否会淘汰-moz-margin:10px?就像我们Mozilla最终支持margin一样,因此我们将忽略所有旧的-moz-margin标记,而仅使用margin标记中的值".

Finally, will margin:10px ever knock out -moz-margin:10px? As in, "We, Mozilla, finally support margin so we are going to ignore all old -moz-margin tags and will just use the value in the margin tag".

推荐答案

例如,如果我想在Webkit,Firefox和其他环境中设置拐角半径,则可以使用以下CSS

For example, if I want to set the corner radius in Webkit, Firefox and other than I can use the following CSS

不,那不是它的工作原理.

No, that isn't how it works.

供应商前缀属性用于实验功能.原因可能是该属性的规范尚未锁定,或者是浏览器实现者知道它们是实现问题.

Vendor prefixed properties are used for experimental features. Either because the specification for the property hasn't been locked down or because the browser implementor knows their are problems with the implementation.

通常,您不应该在生产代码中使用它们,因为它们是实验性的.

In general, you shouldn't use them in production code because they are experimental.

已删除对供应商前缀版本的支持,以保持稳定.

Support for the vendor prefixed versions is removed as support stabilises.

有没有一种方法可以为CSS中的特定浏览器设置任何样式?

Is there a way to set any style for a specific browser in CSS?

有几种方法可以达到这种效果.

There are several methods that have been used for that effect.

解析器错误

通过利用特定CSS引擎中的错误或不受支持的功能(例如,某些版本的IE将忽略属性名称前面的*字符,而其他浏览器将(正确)丢弃整个规则).

By exploiting bugs or unsupported features in specific CSS engines (e.g. some versions of IE will ignore a * character on the front of a property name while other browsers will (correctly) discard the entire rule).

有条件的评论

较旧版本的Internet Explorer支持扩展的HTML注释语法,可用于添加特定于IE某些版本的<link><style>元素.

Older versions of Internet Explorer supported an extended HTML comment syntax that could be used to add <link> or <style> elements specifically for certain versions of IE.

对此的支持已被删除.

JavaScript

在JS中进行浏览器检测之后,可以使用JavaScript将类添加到元素(通常是body元素).

Classes can be added to elements (typically the body element) using JavaScript after doing browser detection in JS.

这篇关于有没有一种方法可以为CSS中的特定浏览器设置任何样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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