浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 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);

  

在线查询          在线测试

【收藏】史上最全的浏览器 CSS & JS Hack 手册的更多相关文章

  1. 【必备】史上最全的浏览器 CSS & JS Hack 手册

    [必备]史上最全的浏览器 CSS & JS Hack 手册   浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技 ...

  2. 【必备】史上最全的浏览器 CSS & JS Hack 手册(转)

    浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技能.如果有一份浏览器 Hack 手册,那查询起来就方便多了.这篇文章就向 ...

  3. 史上最全的浏览器 CSS & JS Hack 手册

    浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技能.如果有一份浏览器 Hack 手册,那查询起来就方便多了.这篇文章就向 ...

  4. 史上最全Html与CSS布局技巧

    单列布局水平居中水平居中的页面布局中最为常见的一种布局形式,多出现于标题,以及内容区域的组织形式,下面介绍四种实现水平居中的方法(注:下面各个实例中实现的是child元素的对齐操作,child元素的父 ...

  5. 史上最全Html和CSS布局技巧

      单列布局水平居中 水平居中的页面布局中最为常见的一种布局形式,多出现于标题,以及内容区域的组织形式,下面介绍四种实现水平居中的方法(注:下面各个实例中实现的是child元素的对齐操作,child元 ...

  6. 史上最全的 UIWebview 的 JS 与 OC 交互

    来源:伯乐在线 - 键盘风筝 链接:http://ios.jobbole.com/89330/ 点击 → 申请加入伯乐在线专栏作者 其实一直想给大家整理一下JS与OC的交互,但是没有合适的机会,今天借 ...

  7. 主流浏览器Css&js hack写法

    参考: BROWSER HACKS 主流浏览器的Hack写法

  8. 史上最全的CSS hack方式一览

    做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来达到大家要求的页面表现.我个人是不太推荐使用hack的,要知道 ...

  9. [转]史上最全的CSS hack方式一览

    做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来达到大家要求的页面表现.我个人是不太推荐使用hack的,要知道 ...

随机推荐

  1. Cocos2d-x 3.2 创建新应用

    1.cd 到 Cocos2d-x 3.2 的目录: 2.python setup.py: 3.source /Users/netty/.bash_profile ; 4.cocos new TestP ...

  2. hdoj1260【简单DP】

    这题就是一个人买还是两个人买,直接选择一下,而且默认是排好了的,就是DP一下,可能不知道DP的人,也是这么写的吧.DP是一种思想啊. #include <bits/stdc++.h> us ...

  3. poj 1743 Musical Theme【二分+SA】

    差分,然后二分长度mid,判断是把height按照min不小于mid分组,取最大最小的sa位置看是否>=mid即可,注意差分后最后答案要+1 #include<iostream> # ...

  4. (二分图最大匹配)51NOD 2006 飞行员配对

    第二次世界大战时期,英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2名飞行员,其中1名是英国飞行员,另1名是外籍飞行员.在众多的飞行员中, ...

  5. hdu 3461 Code Lock 并查集(有点难想到)★★

    #include<stdio.h> #include<math.h> ]; int count; #define mod 1000000007 int find(int x) ...

  6. PostgreSQL - 修改默认端口号

    升级PostgreSQL遇到的问题 之前将PostgreSQL从9.5升级到了10.3版本,安装时将端口设置成了5433,(默认是5432),后来发现在使用psql来restore db会发生语法错误 ...

  7. @ConfigurationProperties和@EnableConfigurationProperties配合使用

    https://blog.csdn.net/u010502101/article/details/78758330 @ConfigurationProperties注解主要用来把properties配 ...

  8. Jmeter之文件下载

    Jmeter文件下载 1.打开jmeter新建线程组—>http请求 2.在百度上选择一个图片下载,选择图片右击复制图片地址 https://ss1.baidu.com/9vo3dSag_xI4 ...

  9. Easy Game LightOJ - 1031

    Easy Game LightOJ - 1031 upd:似乎有复杂度更优越的做法,见http://www.cnblogs.com/hehe54321/p/8431020.html 题意:A和B玩一个 ...

  10. Ilya And The Tree CodeForces - 842C

    ((半个)智商题,主要难度在于实现) 题意:有一棵n个结点组成的树,其根是编号为1的结点.对于每一个结点,生成从根结点走到这个结点的路径(包括自身),选择路径上的一个点或者不选择任何点,使得其它点的最 ...