史上最全的浏览器 CSS & JS Hack 手册
浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异。因此,浏览器兼容成为前端开发人员的必备技能。如果有一份浏览器 Hack 手册,那查询起来就方便多了。这篇文章就向大家分享 Browserhacks 帮我们从网络上收集的各个浏览器特定的 CSS & JavaScript Hack,记得推荐和分享啊!
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 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;
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 {}
媒体查询 Hack
/* 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) {}
JavaScript Hack
/* 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 浏览器
选择器 Hack
/* Chrome 24- and Safari 5- */
::made-up-pseudo-element, .selector {}
媒体查询 Hack
/* Chrome, Safari 3+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {}
JavaScript Hack
/* Chrome */
var isChrome = Boolean(window.chrome);
Safari 浏览器
选择器 Hack
/* 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 {}
媒体查询 Hack
/* Safari 3+, Chrome */
@media screen and (-webkit-min-device-pixel-ratio:0) {}
JavaScript Hack
/* Safari */
var isSafari = /a/.__proto__=='//';
Opera 浏览器
选择器 Hack
/* 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 {}
媒体查询 Hack
/* 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
/* Opera 9.64- */
var isOpera = /^function \(/.test([].sort); /* Opera 12- */
var isOpera = Boolean(window.opera);
史上最全的浏览器 CSS & JS Hack 手册的更多相关文章
- 【必备】史上最全的浏览器 CSS & JS Hack 手册
[必备]史上最全的浏览器 CSS & JS Hack 手册 浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技 ...
- 【必备】史上最全的浏览器 CSS & JS Hack 手册(转)
浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技能.如果有一份浏览器 Hack 手册,那查询起来就方便多了.这篇文章就向 ...
- 【收藏】史上最全的浏览器 CSS & JS Hack 手册
浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技能.如果有一份浏览器 Hack 手册,那查询起来就方便多了.这篇文章就向 ...
- 史上最全Html与CSS布局技巧
单列布局水平居中水平居中的页面布局中最为常见的一种布局形式,多出现于标题,以及内容区域的组织形式,下面介绍四种实现水平居中的方法(注:下面各个实例中实现的是child元素的对齐操作,child元素的父 ...
- 史上最全Html和CSS布局技巧
单列布局水平居中 水平居中的页面布局中最为常见的一种布局形式,多出现于标题,以及内容区域的组织形式,下面介绍四种实现水平居中的方法(注:下面各个实例中实现的是child元素的对齐操作,child元 ...
- 史上最全的 UIWebview 的 JS 与 OC 交互
来源:伯乐在线 - 键盘风筝 链接:http://ios.jobbole.com/89330/ 点击 → 申请加入伯乐在线专栏作者 其实一直想给大家整理一下JS与OC的交互,但是没有合适的机会,今天借 ...
- 主流浏览器Css&js hack写法
参考: BROWSER HACKS 主流浏览器的Hack写法
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结
史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...
- 史上最全的CSS hack方式一览
做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来达到大家要求的页面表现.我个人是不太推荐使用hack的,要知道 ...
随机推荐
- linuxC/C++面试问题总结整理
linuxC/C++面试问题总结整理 因为一些原因重新找工作了,面的linux c/c++,这里把面试中经常碰到的问题总结一下. linuxC/C++面试问题总结整理 单元测试 关键字const 关键 ...
- C++学习之 类
1.类规范 类声明:包括数据成员.成员函数(共有接口)的声明 类方法定义 C++程序员将接口(类)放在头文件中,将实现放在源代码文件中 类设计尽量将共有接口和实现细节分开,数据隐藏(将数据放在私有部分 ...
- Laravel 5.6 视图用Blade语法传递变量和流程控制if 语句和循环语句
Laravel5.6 视图用Blade语法传递变量和流程控制if 语句和循环语句 Laravel 的 View 部分是内置了两套输出系统:直接输出和使用 Blade 引擎“编译”后输出,默认情况下它们 ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
- js实现进度条效果
需求分析: 最近学习javascript客户端脚本语言,学到了两个定时器函数setInterval()和setTimeout(),回想起以前在网页上看到的进度条效果可以使用定时器来实现,所以完成了进度 ...
- 清华大学OS操作系统实验lab1练习知识点汇总
lab1知识点汇总 还是有很多问题,但是我觉得我需要在查看更多资料后回来再理解,学这个也学了一周了,看了大量的资料...还是它们自己的80386手册和lab的指导手册觉得最准确,现在我就把这部分知识做 ...
- helm 替换源的方法
网上找了一个 helm 替换源的方法 挺好用的 mark 一下 helm repo remove stable helm repo add stable https://kubernetes.oss- ...
- 关于PSP(个人软件过程)
在第一堂课时,杨老师就提到了PSP(个人软件过程),但是我从2016年3月10日才开始进行粗略的PSP时间管理统计,这是长迭代,用老师的话“差评”.然后在2016年3月11日下午的软件项目管理上,老师 ...
- 关于“代码规范”,“Review”和“Check list”(续)
在前两天的 关于“代码规范”,“Review”和“Check list” 一文中,我给自己列出了Check list,如下: 1.代码能够工作么?它有没有实现预期的功能,逻辑是否正确等. ...
- Entity Framework(EF) Code First将实体中的string属性映射成text类型的几种方式
1.通过ColumnType属性设置 [Column(TypeName="text")] public string Text { get; set; } 在进行以上属性设置时,请 ...