浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异。因此,浏览器兼容成为前端开发人员的必备技能。如果有一份浏览器 Hack 手册,那查询起来就方便多了。这篇文章就向大家分享 Browserhacks 帮我们从网络上收集的各个浏览器特定的 CSS & JavaScript Hack,记得推荐和分享啊!

IE 选择器 Hack

1
2
3
/* IE 6 and below */
* html .selector  {}
.suckyie6.selector {} /* .suckyie6 can be any unused class */
1
2
/* IE 7 and below */
.selector, {}
1
2
3
4
/* IE 7 */
*:first-child+html .selector {}
.selector, x:-IE7 {}
*+html .selector {}
/* Everything but IE 6 */
html > body .selector {}
1
2
3
/* Everything but IE 6/7 */
html > /**/ body .selector {}
head ~ /* */ body .selector {}
1
2
3
4
5
/* Everything but IE 6/7/8 */
:root *> .selector {}
body:last-child .selector {}
body:nth-of-type(1) .selector {}
body:first-of-type .selector {}

IE 属性/值 Hack

1
2
3
/* IE 6 */
.selector { _colorblue; }
.selector { -colorblue; }
1
2
3
/* IE 6/7 - acts as an !important */
.selector { colorblue !ie; }
/* string after ! can be anything */
1
2
3
4
5
6
7
/* IE 6/7 - any combination of these characters:
 ! $ & * ( ) = % + @ , . / ` [ ] # ~ ? : < > | */
.selector { !colorblue; }
.selector { $colorblue; }
.selector { &colorblue; }
.selector { *colorblue; }
/* ... */
1
2
3
/* IE 8/9 */
.selector { colorblue\0/; }
/* must go at the END of all rules */
1
2
/* IE 9/10 */
.selector:nth-of-type(1n) { colorblue\9; }
1
2
3
/* IE 6/7/8/9/10 */
.selector { colorblue\9; }
.selector { color/*\**/blue\9; }
1
2
/* Everything but IE 6 */
.selector { color/**/blue; }

IE Media Query Hack

1
2
/* IE 6/7 */
@media screen\9 {}
1
2
/* IE 8 */
@media \0screen {}
1
2
/* IE 9/10, Firefox 3.5+, Opera */
@media screen and (min-resolution: +72dpi) {}
1
2
/* IE 10+ */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {}
1
2
/* IE 6/7/8 */
@media \0screen\,screen\9 {}
1
2
/* IE 8/9/10 & Opera */
@media screen\0 {}
1
2
/* IE 9/10 */
@media screen and (min-width:0\0) {}
1
2
/* Everything but IE 6/7/8 */
@media screen and (min-width400px) {}

IE JavaScript Hack

1
2
3
/* IE 6 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 6]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1;
1
2
3
4
/* IE 7 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 7]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1;
navigator.appVersion.indexOf("MSIE 7.")!=-1
1
2
/* IE <= 8 */
var isIE = '\v'=='v';
1
2
3
/* IE 8 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 8]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1;
1
2
3
/* IE 9 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 9]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1;
1
2
/* IE 10 */
var isIE = eval("/*@cc_on!@*/false") && document.documentMode === 10;
1
2
/* IE 10 */
var isIE = document.body.style.msTouchAction != undefined;

Firefox 浏览器

  选择器 Hack

1
2
/* Firefox 1.5 */
body:empty .selector {}
1
2
/* Firefox 2+ */
.selector, x:-moz-any-link {}
1
2
/* Firefox 3+ */
.selector, x:-moz-any-link; x:default {}
1
2
/* Firefox 3.5+ */
body:not(:-moz-handler-blocked) .selector {}

  媒体查询 Hack

1
2
/* Firefox 3.5+, IE 9/10, Opera */
@media screen and (min-resolution: +72dpi) {}
1
2
/* Firefox 3.6+ */
@media screen and (-moz-images-in-menus:0) {}
1
2
/* Firefox 4+ */
@media screen and (min--moz-device-pixel-ratio:0) {}

  JavaScript Hack

1
2
/* Firefox */
var isFF = !!navigator.userAgent.match(/firefox/i);
1
2
/* Firefox 2 - 13 */
var isFF = Boolean(window.globalStorage);
1
2
/* Firefox 2/3 */
var isFF = /a/[-1]=='a';
1
2
/* Firefox 3 */
var isFF = (function x(){})[-5]=='x';

Chrome 浏览器

  选择器 Hack

1
2
/* Chrome 24- and Safari 5- */
::made-up-pseudo-element, .selector {}

  

  媒体查询 Hack

1
2
/* Chrome, Safari 3+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {}

  

  JavaScript Hack

1
2
/* Chrome */
var isChrome = Boolean(window.chrome);

  

Safari 浏览器

  选择器 Hack

1
2
3
/* Safari 2/3 */
html[xmlns*=""] body:last-child .selector {}
html[xmlns*=""]:root .selector  {}
1
2
/* Safari 2/3.1, Opera 9.25 */
*|html[xmlns*=""] .selector {}
1
2
/* Safari 5- and Chrome 24- */
::made-up-pseudo-element, .selector {}

  

  媒体查询 Hack

1
2
/* Safari 3+, Chrome */
@media screen and (-webkit-min-device-pixel-ratio:0) {}

  

  JavaScript Hack

1
2
/* Safari */
var isSafari = /a/.__proto__=='//';

  

Opera 浏览器

  选择器 Hack

1
2
/* Opera 9.25, Safari 2/3.1 */
*|html[xmlns*=""] .selector {}
1
2
/* Opera 9.27 and below, Safari 2 */
html:first-child .selector {}
1
2
/* Opera 9.5+ */
noindex:-o-prefocus, .selector {}

  

  媒体查询 Hack

1
2
/* Opera 7 */
@media all and (min-width0px){}
1
2
/* Opera 12- */
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {}
1
2
/* Opera, Firefox 3.5+, IE 9/10 */
@media screen and (min-resolution: +72dpi) {}
1
2
/* Opera, IE 8/9/10 */
@media screen {}

  

  JavaScript Hack

1
2
/* Opera 9.64- */
var isOpera = /^function \(/.test([].sort);
1
2
/* Opera 12- */
var isOpera = Boolean(window.opera);

  

在线查询          在线测试

最新文章

  1. 【BZOJ】4056: [Ctsc2015]shallot
  2. 【原创】开源Math.NET基础数学类库使用(12)C#随机数扩展方法
  3. 分享我基于NPOI+ExcelReport实现的导入与导出EXCEL类库:ExcelUtility (续3篇-导出时动态生成多Sheet EXCEL)
  4. Spring应用教程-2 方法注入
  5. HDU 4944 FSF’s game 一道好题
  6. 拼图游戏 v1.1
  7. bootstrap小例子等
  8. 【 D3.js 选择集与数据详解 — 1 】 使用datum()绑定数据
  9. 细说php(六) 数组
  10. hdu - 3572 - Task
  11. intellij idea 学习
  12. oracle 数据库管理员
  13. Android Selector原理
  14. systemverilog.vim
  15. 7、zabbix使用进阶(03)
  16. json字符转对象之new Function(&#39;return &#39; + str)
  17. 【开发工具之eclipse】7、eclipse代码自动提示,eclipse设置代码自动提示
  18. 在离线安装gazebo的时候可能在运行turtlebot_gazebo的时候会出现问题
  19. asp.net MVC学习的一些总结
  20. CF623D birthday 贪心 概率期望

热门文章

  1. k8s-RBAC授权-十六
  2. python学习笔记5-自定义函数
  3. django QQ认证登录
  4. Windows 下openssl安装与配置
  5. Moctf--没时间解释了
  6. hdu3926 Hand in Hand 同构图
  7. bzoj1854 [Scoi2010]游戏【构图 并查集】
  8. Baker Vai LightOJ - 1071
  9. 贪心 HDOJ 5090 Game with Pearls
  10. sql基础语法-创建表和约束