Skip to content

Instantly share code, notes, and snippets.

@Yago
Created January 29, 2014 10:47
Show Gist options
  • Save Yago/d72a8a558f84017314b9 to your computer and use it in GitHub Desktop.
Save Yago/d72a8a558f84017314b9 to your computer and use it in GitHub Desktop.
CSS - Browsers hacks
CSS HACKS
-----------------------------------------------------------------
All except IE5
selector { property/**/: value; }
All except IE5/Mac
/*\*/ selector { property:value; } /**/
IE5/Mac
/*\*//*/ selector { property:value; } /**/
All except IE5.5
selector { property: /**/value; }
IE <= 5.5
selector { property:value; p\roperty: normal-value; }
All except IE <= 6
html>body selector { property:value; }
IE <= 6
/*\*/ * html selector { property:value; } /**/
All except IE6 standards
selector { property /**/: value; }
IE6+ quirks and IE5 (= all IE/Win quirks)
* html selector { property /**/: value; }
IE6
selector { _property:value; }
* html selector { property:value; }
IE <= 7
html >/**/body selector { property:value; }
body*selector{ property:value; }
selector { property:value !important!;}
selector { property:value !inIE;}
IE7
*:first-child+html selector { property:value; }
*+html 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; }
selector { ,property:value; }
selector { <property:value; }
selector { >property:value; }
selector { /property:value; }
selector { ?property:value; }
IE >= 7
selector { property /*\**/: value\9; }
IE < 8
selector\ { property:value; }
IE 8
selector { property:value\9; }
selector { property:value\0; }
IE8 & IE9
selector { property:value; \ ;}
selector { property:value;\0/;}
IE9
:root selector { property:value \ ;}
:root selector { property:value \0;}
@media all and (min-width:0) { selector { property:value \0/; } }
IE9 & Opera 10
:root selector { property:value\0;}
IE
selector { *property:value; }
Opera 7
@ Media all and (min-width: 0px) { selector { property:value; } }
Opera <= 9
@media all and (min-width: 0px){ head~body selector { property:value; } }
html:first-child selector { property:value; }
Opera <= 9.5
@media all and (min-width: 0px) { html:first-child selector { property:value; } }
Opera >= 9.5
x:-o-prefocus, selector { property:value; }
Opera < 10 & Chrome
selector { -bracket-:hack(;property:value;); }
Opera >= 10
@media not all and (-webkit-min-device-pixel-ratio:0) { selector { property:value; } }
Opera
@media all and (min-width: 0px){ selector { property:value; } }
Opera & IE <= 6
head: first-child + body selector { property:value; }
Safari 3
selector:not(:root:root) { property:value; }
Safari
@media all and (-webkit-min-device-pixel-ratio: 0) { selector { property:value; } }
html:lang(en)>body selector { property:value; }
Mozilla & Safari
html: not ([dummy]) selector { property:value; }
Chrome & Safari
@media screen and (-webkit-min-device-pixel-ratio:0) { selector { property:value; } }
Chrome
body:nth-of-type(1) selector { color: #333333; }
selector { (-bracket-:hack;property:value;); }
selector { -bracket-:hack[;property:value;]; }
Firefox 1.5 & 2
body:empty selector { property:value; }
Firefox >= 1.5
@-moz-document url-prefix() { selector { property:value; } }
Firefox 3
html&gt;/**/body .className, x:-moz-any-link, x:default { selector { property:value; } }
Firefox 4-6
:-moz-any(selector} { property:value; }
Firefox
@-moz-document url-prefix() { selector { property:value; } }
html&gt;/**/body selector { property:value; }
CSS HACKS in (X)HTML
-----------------------------------------------------------------
Netscape
<style type="text/css"> @ import url ('style.css') </ style>
<- & {True}; <style type="text/css"> selector { property:value; } </ style> ->
Opera
<link rel="stylesheet" type="text/nonsense" href="style.css" />
Mozilla
<link rel="extra-keyword stylesheet" type="text/css" href="style.css"/>
Safari
<link rel="extra-keyword stylesheet" type="text/css" href="style.css"/>
IE (x = version #)
<!--[if IE x]> CODE <![endif]-->
<!--[if IE x]> CODE <![endif]-->
<!--[if gte IE x]> CODE <![endif]-->
<!--[if gt IE x]> CODE <![endif]-->
<!--[if lte IE x]> CODE <![endif]-->
<!--[if lt IE x]> CODE <![endif]-->
<!--[!IE x]> CODE <![endif]-->
Examples:
<- [If gte IE x]> <style type="text/css"> selector { property:value; } </ style> <! [Endif] ->
or
<- [If gte IE x]> <style type="text/css"> @ import url ('styles.css') </ style> <[endif] ->
Only IE
<!--[if IE]> CODE <![endif]-->
All browsers except IE
<!--[if !IE]>< --> CODE <!-- ><![endif]-->
@meddlenz
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment