使用条件注释很容易使用特定于浏览器的CSS规则来定位Internet Explorer: css
<!--[if IE 6]> ...include IE6-specific stylesheet here... <![endif]-->
有时,Gecko引擎(Firefox)行为不端。 使用CSS规则而不是单个其余浏览器仅针对Firefox的最佳方法是什么? 也就是说,Internet Explorer不只应该忽略Firefox规则,还应该忽略WebKit和Opera。 html
注意:我正在寻找一个“干净”的解决方案。 在我看来,使用JavaScript浏览器嗅探器向个人HTML添加“firefox”类并不符合要求。 我宁愿看到一些取决于浏览器功能的东西,就像条件评论只对IE有“特殊”... web
如下是一些仅针对Firefox浏览器的浏览器黑客, chrome
_:-moz-tree-row(hover), .selector {}
var isFF = !!window.sidebar; var isFF = 'MozAppearance' in document.documentElement.style; var isFF = !!navigator.userAgent.match(/firefox/i);
这将是适用的,Firefox 3.6及更高版本 浏览器
@media screen and (-moz-images-in-menus:0) {}
若是您须要更多信息,请访问browserhacks app
使用-engine特定规则可确保有效的浏览器定位。 ide
<style type="text/css"> //Other browsers color : black; //Webkit (Chrome, Safari) @media screen and (-webkit-min-device-pixel-ratio:0) { color:green; } //Firefox @media screen and (-moz-images-in-menus:0) { color:orange; } </style> //Internet Explorer <!--[if IE]> <style type='text/css'> color:blue; </style> <![endif]-->
更新 (来自@Antoine评论) url
你能够使用@supports
spa
@supports (-moz-appearance:none) { h1 { color:red; } }
<h1>This should be red in FF</h1>
更多关于@supports
信息 firefox
如下代码倾向于抛出Style lint警告:
@-moz-document url-prefix() { h1 { color: red; } }
而是使用
@-moz-document url-prefix('') { h1 { color: red; } }
帮帮我了! 从这里得到了样式lint警告的解决方案
如下是如何处理三种不一样的浏览器:IE,FF和Chrome
<style type='text/css'> /*This will work for chrome */ #categoryBackNextButtons { width:490px; } /*This will work for firefox*/ @-moz-document url-prefix() { #categoryBackNextButtons{ width:486px; } } </style> <!--[if IE]> <style type='text/css'> /*This will work for IE*/ #categoryBackNextButtons { width:486px; } </style> <![endif]-->