各种各样的hack。
http://itakeo.com/blog/2015/11/16/allhack/?none=123
Android
Selector Hacks
.selector:not(*:root) {}
JavaScript Hacks
var isChromium =!!window.chrome;
Media Query Hacks
@media screen and (min-width:0\0) {}
Chrome
Selector Hacks
.selector:not(*:root) {}
Supports Hacks
@supports (-webkit-appearance:none) {}
Property/Value Hacks
.selector { (;property: value;);}.selector { [;property: value;];}
JavaScript Hacks
var isChromium =!!window.chrome;
var isWebkit ='WebkitAppearance'in document.documentElement.style;
var isChrome =!!window.chrome &&!!window.chrome.webstore;
Media Query Hacks
@media \\0 screen {}
@media all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm) {.selector {}}
Firefox
Selector Hacks
body:empty .selector {}
body:last-child .selector, x:-moz-any-link {}
body:last-child .selector, x:-moz-any-link, x:default {}
body:not(:-moz-handler-blocked) .selector {}
_::-moz-progress-bar, body:last-child .selector {}
_::-moz-range-track, body:last-child .selector {}
_:-moz-tree-row(hover), .selector {}
_::selection, .selector:not([attr*='']) {}
Supports Hacks
@supports (-moz-appearance:meterbar) {}
@supports (-moz-appearance:meterbar) and (display:flex) {}
@supports (-moz-appearance:meterbar) and (cursor:zoom-in) {}
@supports (-moz-appearance:meterbar) and (background-attachment:local) {}
@supports (-moz-appearance:meterbar) and (image-orientation:90deg) {}
@supports (-moz-appearance:meterbar) and (all:initial) {}
@supports (-moz-appearance:meterbar) and (list-style-type:japanese-formal) {}
@supports (-moz-appearance:meterbar) and (background-blend-mode:difference,normal) {}
JavaScript Hacks
var isFF =!!window.sidebar;
var isFF ='MozAppearance'in document.documentElement.style;
var isFF =!!navigator.userAgent.match(/firefox/i);
var isFF =typeof InstallTrigger !=='undefined';
var isFF =!!window.globalStorage;
var isFF =/a/[-1]=='a';
var isFF =(function x(){})[-6]=='x';
var isFF =(function x(){})[-5]=='x';
Media Query Hacks
@media \0 all {}
@media screen and (-moz-images-in-menus:0) {}
@media screen and (min--moz-device-pixel-ratio:0) {}
@media all and (min--moz-device-pixel-ratio:0) and (min-resolution: .001dpcm) {}@media all and (-moz-images-in-menus:0) and (min-resolution: .001dpcm) {}
@media all and (min--moz-device-pixel-ratio:0) {@media (min-width: 0px) {}}@media all and (-moz-images-in-menus:0) {@media (min-width: 0px) {}}
@media all and (min--moz-device-pixel-ratio:0) and (min-resolution: 3e1dpcm) {}
Miscellaneous
@-moz-document url-prefix() {}
Internet Explorer
Selector Hacks
* html .selector {}.unused-class.selector {}
html > body .selector {}
*:first-child+html .selector {}.selector, x:-IE7 {}*+html .selector {}body*.selector {}
.selector\ {}
html >/**/body .selector {}head ~ /**/body .selector {}
.selector, {}
_::selection, .selector:not([attr*='']) {}
:root .selector {}body:last-child .selector {}body:nth-of-type(1) .selector {}body:first-of-type .selector {}.selector:not([attr*='']) {}
html[lang='\en'] .selector {}
_:-ms-input-placeholder, :root .selector {}
_:-ms-fullscreen, :root .selector {}
Property/Value Hacks
.selector { _property: value;}.selector {-property: value;}
.selector {property: value\9;}.selector { property/*\**/: value\9;}
Any combination of these characters: ! $ & * ( ) = % + @ , . / ` [ ] # ~ ? : < > |
.selector { !property: value;}.selector { $property: value;}.selector {&property: value;}.selector { *property: value;}.selector { )property: value;}.selector { =property: value;}.selector { %property: value;}.selector { +property: value;}.selector { @property: value;}.selector { ,property: value;}.selector { .property: value;}.selector { /property: value;}.selector { `property: value;}.selector { ]property: value;}.selector { #property: value;}.selector { ~property: value;}.selector { ?property: value;}.selector {:property: value;}.selector { |property: value;}
.selector {property: value !ie;}
JavaScript Hacks
查看IE版本
var ieVersion =/*@cc_on (function() {switch(@_jscript_version) {case 1.0: return 3; case 3.0: return 4; case 5.0: return 5; case 5.1: return 5; case 5.5: return 5.5; case 5.6: return 6; case 5.7: return 7; case 5.8: return 8; case 9: return 9; case 10: return 10;}})() || @*/0;
var isIE = document.all &&!window.XMLHttpRequest;
var isIE =!!window.ActiveXObject;
var isIE = document.all && document.compatMode;
var isIE = document.all &&!document.querySelector;
var isIE = document.all && window.XMLHttpRequest &&!document.querySelector;
var isIE = document.all && window.XMLHttpRequest;
var isIE = navigator.appVersion.indexOf("MSIE 7.")!==-1;
var isIE =!+'\v1';
var isIE ='\v'=='v';
var isIE = document.all && document.querySelector;
var isIE = document.all &&!document.addEventListener;
var isIE = document.all && document.querySelector &&!document.addEventListener;
var isIE = document.all && document.addEventListener;
var isIE = document.all && document.addEventListener &&!window.atob;
var isIE = document.all &&!window.atob;
var isIE =/*@cc_on!@*/false;
var isIE = document.all && window.atob;
查看IE版本
var ieVersion =(function(){if(new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent)!=null){return parseFloat( RegExp.$1);}else{returnfalse;}})();
var isIE = eval("/*@cc_on!@*/false")&& document.documentMode ===10;
var isIE = document.body.style.msTouchAction !== undefined;
var isIE = window.navigator.msPointerEnabled;
var isIE ='behavior'in document.documentElement.style &&'-ms-user-select'in document.documentElement.style;
var isIE ='-ms-scroll-limit'in document.documentElement.style &&'-ms-ime-align'in document.documentElement.style;
Media Query Hacks
@media screen\9 {}
@media \0screen\,screen\9 {}
@media \0screen {}
@media screen and (min-width:0\0) {}
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {}
@media screen {@media (min-width: 0px) {}}
Conditional comments
<!--[if IE 6]> Internet Explorer 6 <![endif]--><!--[if IE 7]> Internet Explorer 7 <![endif]--><!--[if IE 8]> Internet Explorer 8 <![endif]--><!--[if IE 9]> Internet Explorer 9 <![endif]-->
<!--[if lte IE 6]> Internet Explorer 6 or less <![endif]--><!--[if lte IE 7]> Internet Explorer 7 or less <![endif]--><!--[if lte IE 8]> Internet Explorer 8 or less <![endif]--><!--[if lte IE 9]> Internet Explorer 9 or less <![endif]-->
<!--[if gte IE 6]> Internet Explorer 6 or greater <![endif]--><!--[if gte IE 7]> Internet Explorer 7 or greater <![endif]--><!--[if gte IE 8]> Internet Explorer 8 or greater <![endif]--><!--[if gte IE 9]> Internet Explorer 9 or greater <![endif]-->
<!--[if IE]> Internet Explorer 9- <![endif]-->
<!--[if !IE]><!--> Everything but Internet Explorer ≤9 <!--<![endif]-->
Opera
Selector Hacks
*|html[xmlns*=""] .selector {}
html:first-child .selector {}
_:-o-prefocus, body:last-child .selector {}
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {}
.selector:not(*:root) {}
Supports Hacks
@supports (-webkit-appearance:none) {}
Property/Value Hacks
.selector { (;property: value;);}.selector { [;property: value;];}
JavaScript Hacks
var isOpera =/^function \(/.test([].sort);
var isOpera = window.opera && window.opera.version()== X;
var isOpera =!!window.opera;
var isChromium =!!window.chrome;
var isWebkit ='WebkitAppearance'in document.documentElement.style;
var isOpera =!!window.opera ||/opera|opr/i.test(navigator.userAgent);
Media Query Hacks
@media (min-resolution: .001dpcm) {_:-o-prefocus, .selector {}}
@media all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm) {.selector {}}
Opera Mini
JavaScript Hacks
div isOperaMini = Object.prototype.toString.call(window.operamini)==='[object OperaMini]';
var isOperaMini =(navigator.userAgent.indexOf('Opera Mini')>-1);
Safari
Selector Hacks
.selector:not(*:root) {}
html:first-child .selector {}
html[xmlns*=""] body:last-child .selector {}html[xmlns*=""]:root .selector {}
*|html[xmlns*=""] .selector {}
_::-moz-svg-foreign-content, :root .selector {}
Property/Value Hacks
.selector { (;property: value;);}.selector { [;property: value;];}
JavaScript Hacks
var isWebkit ='WebkitAppearance'in document.documentElement.style;
var isSafari =/a/.__proto__=='//';
var isSafari =/constructor/i.test(window.HTMLElement);
var isSafari =!!navigator.userAgent.match(/safari/i)&&!navigator.userAgent.match(/chrome/i)&&typeof document.body.style.webkitFilter !=="undefined"&&!window.chrome;
Media Query Hacks
@media screen and (min-width:0\0) {}
@media screen {@media (min-width: 0px) {}}
@media \\0 screen {}