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

移动手机iphone media query Hack

/*
* media query for iPhone 4/4s
* if targeting 2G/3G/3GS/4/4S, then remove "-webkit-min-device-pixel-ratio: 2" media query condition.
*/
@media only screen
and (device-aspect-ratio: 2/3)
and (-webkit-device-pixel-ratio: 2)
and (orientation : portrait) {
} /*
* media query for iPhone 5/5S
*/
@media only screen
and (device-aspect-ratio: 40/71)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation : portrait) {
}
/*
* media query for iPhone 6
*/
@media only screen
and (device-aspect-ratio: 667/375)
and (-webkit-min-device-pixel-ratio : 2)
and (orientation : portrait) {
/* STYLES GO HERE */
} /*
* media query for iPhone 6+
*/
@media only screen
and (device-aspect-ratio: 16/9)
and (-webkit-device-pixel-ratio: 3)
and (orientation : portrait) {
/* STYLES GO HERE */
}

下面转载自:http://websqq.org/archives/1428, http://websqq.org/archives/1161

IE选择器 Hack

/* IE 6 and below */
* html .selector {}
.suckyie6.selector {} /* .suckyie6 can be any unused class */
/* IE 7 and below */
.selector, {} /* IE 7 */
*:first-child+html .selector {}
.selector, x:-IE7 {}
*+html .selector {} /* Everything but IE 6 */
html > body .selector {} /* Everything but IE 6/7 */
html > /**/ body .selector {}
head ~ /* */ body .selector {} /* 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

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

IE Media Query Hack

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

IE Javascript Hack

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

媒体查询 Hack--Firefox,Chrome,Opera

/* Firefox 3.5+, IE 9/10, Opera */
@media screen and (min-resolution: +72dpi) {}
/* Firefox 3.6+ */
@media screen and (-moz-images-in-menus:0) {} /* Firefox 4+ */
@media screen and (min--moz-device-pixel-ratio:0) {} /* Chrome, Safari 3+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {} /* Opera 7 */
@media all and (min-width: 0px){}
/* Opera 12- */
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {} /* Opera, Firefox 3.5+, IE 9/10 */
@media screen and (min-resolution: +72dpi) {} /* Opera, IE 8/9/10 */
@media screen {}

Javascript Hack--Firefox,Chrome,Opera

/* Firefox */
var isFF = !!navigator.userAgent.match(/firefox/i);
/* Firefox 2 - 13 */
var isFF = Boolean(window.globalStorage); /* Firefox 2/3 */
var isFF = /a/[-1]=='a'; /* Firefox 3 */
var isFF = (function x(){})[-5]=='x'; /* Chrome */
var isChrome = Boolean(window.chrome); /* Safari */
var isSafari = /a/.__proto__=='//'; /* Opera 9.64- */
var isOpera = /^function \(/.test([].sort);
/* Opera 12- */
var isOpera = Boolean(window.opera);

Firefox 浏览器   选择器Hack

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

Chrome,Safari,Opera浏览器   选择器 Hack

/* Chrome 24- and Safari 5- */
::made-up-pseudo-element, .selector {} /* Safari 2/3 */
html[xmlns*=""] body:last-child .selector {}
html[xmlns*=""]:root .selector {} /* Safari 2/3.1, Opera 9.25 */
*|html[xmlns*=""] .selector {} /* Safari 5- and Chrome 24- */
::made-up-pseudo-element, .selector {} /* Opera 9.25, Safari 2/3.1 */
*|html[xmlns*=""] .selector {} /* Opera 9.27 and below, Safari 2 */
html:first-child .selector {} /* Opera 9.5+ */
noindex:-o-prefocus, .selector {}

【必备】史上最全的浏览器 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. 新手必备 | 史上最全的PyTorch学习资源汇总

    目录: PyTorch学习教程.手册 PyTorch视频教程 PyTorch项目资源      - NLP&PyTorch实战      - CV&PyTorch实战 PyTorch论 ...

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

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

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

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

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

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

随机推荐

  1. Java Servlet(十):JSTL核心标签库

    JSTL全名称:JaveServer Pages Standard Tag Library.JSTL是由JCP(Java Community Process)所定制的标准规范,它主要提供给Java W ...

  2. Log4j用法

    本篇仅仅是简单介绍了在写一个测试例子时,怎么使用log4j的经验,如果用于生产环境,估计还需要在深入一步去了解更多详细的配置信息. log4j.properties 配置信息: log4j.rootL ...

  3. Unity NGUI 资源下载

    https://www.assetstore.unity3d.com/cn/#!/content/2413 版本: 3.9.1 下载地址 密码:amtz

  4. Clob类型转化String类型

    Clob clob=rs.getClob(列数); Clob clob=rs.getClob("列名");String content=clob.getSubString((lon ...

  5. Unicode、UTF-8、UTF-16和UTF-32的区别

    Unicode是一个巨大的字符集,给世界上所有的字符定义了一个唯一编码.其仅仅规定了每个符号的二进制代码,没有制定细化的存储规则.UTF-8.UTF-16.UTF-32才是Unicode的存储格式定义 ...

  6. [Effective JavaScript 笔记]第7章:并发--个人总结

    前言 这一章的内容学到了事件队列和异步的API.js只是运行在其他应用程序的脚本语言.js即依赖于应用程序,也独立与应用程序.可以使它可以在多平台,多种环境上运行.ECMAScript标准中没有关于并 ...

  7. 互联网中级Javascript面试题

    互联网中级Javascript面试题 1.实现一个函数clone,可以对JavaScript中的5种主要的数据类型(包括Number.String.Object.Array.Boolean)进行值复制 ...

  8. WLST 命令和变量

    下列部分将详细描述 WLST 命令和变量.主题包括:  WSLT 命令类别概述  浏览命令  控制命令  部署命令  诊断命令  编辑命令  信息命令  生命周期命令  节点管理器命令  树命令  W ...

  9. 初识python第二天(2)

    整理Python常见数据类型内置函数的使用方法如下: 一.int 首先我们来查看一下int包含了哪些函数 #python3.x print(dir(int)) #['__abs__', '__add_ ...

  10. node.js报错总结

    1. Error: EISDIR, read 这个报错是目标不应该是文件夹,而是其他类型,本错误出现在使用fs.createReadStream()里参数传递了个文件夹,但是应该传递个文件. 参考地址 ...