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

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. SELECT * FROM ( S ...

  2. E20170503-hm

    leading edge  前沿 trailing edge 后缘 trail v跟踪 top edge 顶边 bottom edge  底边 intrinsic   adj 固有的 intrinsi ...

  3. HDU6050: Funny Function(推公式+矩阵快速幂)

    传送门 题意 利用给出的式子求\(F_{m,1}\) 分析 直接推公式(都是找规律大佬) \(n为偶数,F_{m,1}=\frac{2(2^n-1)^{m-1}}3\) \(n为奇数,F_{m,1}= ...

  4. 安装kibana

    下载kibana5.1.1或者5.1.2版本的deb包,然后用dpkg命令安装 安装后启动位置在 /usr/share/kibana/bin中,在该目录下运行 ./kibana 即可启动 启动前应该先 ...

  5. Jquery | 基础 | 属性过滤选择器

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. redis的多路复用io

    redis基于reactor开发了自己的网路事件处理器,被称为文件事件处理器.使用io多路复用来同时监听多个套接字,来响应客户端的连接应答.命令请求.命令恢复.多路复用技术使得redis可以使用单进程 ...

  7. ssh密钥分发之二:使用sshpass配合ssh-kopy-id编写脚本批量分发密钥:

    使用sshpass配合ssh-kopy-id编写脚本批量分发密钥: 首先sshpass是一个ssh连接时的免交互工具,首先要安装一下: yum install sshpass -y 接下来我们就可以使 ...

  8. 线段树(单点更新) HDOJ 4288 Coder

    题目传送门 #include <cstdio> #include <cstring> #define lson l, m, rt << 1 #define rson ...

  9. 对protected修饰符的范围用代码说明(同时说明用protected修饰的属性,在继承时,一定程度上破坏了封装)

    目录结构: 本类: 本包: 子孙类: 其他包:

  10. SPRING-BOOT系列之SpringBoot的诞生及其和微服务的关系

    转载自 : https://www.cnblogs.com/ityouknow/p/9034377.html 微服务架构 微服务的诞生并非偶然,它是在互联网高速发展,技术日新月异的变化以及传统架构无法 ...