当前位置: 首页 > news >正文

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

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

转载于:https://www.cnblogs.com/JoannaQ/p/4285837.html

相关文章:

  • ElementUI Tree树形控件renderContent return时报错
  • iOS Widget简单使用
  • FaceBook页面加载技术
  • 缴款日后流动性仍紧 央票利率再现“倒挂”
  • HIDKomponente使用读写Hid设备(转)
  • setPreferredSize和setSize的区别及用法
  • 人们为何喜欢在社交网络发布个人状态?
  • iOS常用动画
  • 信息增益的特征选择方法
  • 关于自定义强类型实体类的一点困惑
  • 记录学习MVC过程,MVC验证(四)
  • nginx 转发 header 数据丢失
  • unity5,UI Button too small on device than in Game View解决办法
  • DotNetTextBox V3.0 所见即所得编辑器控件Ver3.2.4 Free(免费版)
  • JavaScript 函数调用时带括号和不带括号的区别
  • Android 初级面试者拾遗(前台界面篇)之 Activity 和 Fragment
  • axios 和 cookie 的那些事
  • CentOS6 编译安装 redis-3.2.3
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • extract-text-webpack-plugin用法
  • iOS 系统授权开发
  • Java多线程(4):使用线程池执行定时任务
  • java概述
  • OSS Web直传 (文件图片)
  • QQ浏览器x5内核的兼容性问题
  • TypeScript实现数据结构(一)栈,队列,链表
  • ucore操作系统实验笔记 - 重新理解中断
  • web标准化(下)
  • 从输入URL到页面加载发生了什么
  • 工作踩坑系列——https访问遇到“已阻止载入混合活动内容”
  • 类orAPI - 收藏集 - 掘金
  • 强力优化Rancher k8s中国区的使用体验
  • 算法-插入排序
  • 微信公众号开发小记——5.python微信红包
  • 一文看透浏览器架构
  • Java数据解析之JSON
  • 通过调用文摘列表API获取文摘
  • ​Linux Ubuntu环境下使用docker构建spark运行环境(超级详细)
  • (39)STM32——FLASH闪存
  • (4)事件处理——(6)给.ready()回调函数传递一个参数(Passing an argument to the .ready() callback)...
  • (6)STL算法之转换
  • (C语言)球球大作战
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (Ruby)Ubuntu12.04安装Rails环境
  • (附源码)springboot 房产中介系统 毕业设计 312341
  • (牛客腾讯思维编程题)编码编码分组打印下标题目分析
  • (十)【Jmeter】线程(Threads(Users))之jp@gc - Stepping Thread Group (deprecated)
  • .net Signalr 使用笔记
  • .NET WebClient 类下载部分文件会错误?可能是解压缩的锅
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:Bluetooth组件
  • @kafkalistener消费不到消息_消息队列对战之RabbitMq 大战 kafka
  • @我的前任是个极品 微博分析
  • [ vulhub漏洞复现篇 ] JBOSS AS 5.x/6.x反序列化远程代码执行漏洞CVE-2017-12149
  • [20180312]进程管理其中的SQL Server进程占用内存远远大于SQL server内部统计出来的内存...
  • [c++] C++多态(虚函数和虚继承)