<!doctype html> <html> <head> <title>IE10/11 Media Query Test</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <style> @media all and (-ms-high-contrast:none) { .foo { color: gold} /* IE10 */ *::-ms-backdrop, .foo { color: pink} /* IE11 */ } </style> </head> <body> <div class="foo">Hello World</div> </body> </html>
In the light of the evolving thread, I have updated the below:
IE 11 (and above..)
_:-ms-fullscreen, :root .foo { property:value; }
IE 10 and above
_:-ms-lang(x), .foo { property:value; }
or
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.foo{property:value;}
}
IE 10 only
_:-ms-lang(x), .foo { property:value\9; }
IE 9 and above
@media screen and (min-width:0\0) and (min-resolution: +72dpi) {
//.foo CSS
.foo{property:value;}
}
IE 9 and 10
@media screen and (min-width:0\0) {
.foo /* backslash-9 removes.foo & old Safari 4 */
}
IE 9 only
@media screen and (min-width:0\0) and (min-resolution: .001dpcm) {
//.foo CSS
.foo{property:value;}
}
IE 8,9 and 10
@media screen\0 {
.foo {property:value;}
}
IE 8 Standards Mode Only
.foo { property /*\**/: value\9 }
IE 8
html>/**/body .foo {property:value;}
or
@media \0screen {
.foo {property:value;}
}
IE 7
*+html .foo {property:value;}
or
*:first-child+html .foo {property:value;}
IE 6, 7 and 8
@media \0screen\,screen\9 {
.foo {property:value;}
}
IE 6 and 7
@media screen\9 {
.foo {property:value;}
}
or
.foo { *property:value;}
or
.foo { #property:value;}
IE 6, 7 and 8
@media \0screen\,screen\9 {
.foo {property:value;}
}
IE 6
* html .foo {property:value;}
or
.foo { _property:value;}
Javascript alternatives
Modernizr
Modernizr runs quickly on page load to detect features; it then creates a JavaScript object with the results, and adds classes to the html element
User agent selection
Javascript:
var b = document.documentElement;
b.setAttribute('data-useragent', navigator.userAgent);
b.setAttribute('data-platform', navigator.platform );
b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');
Adds (e.g) the below to html
element:
data-useragent='Mozilla/5.0 (compatible; M.foo 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'
data-platform='Win32'
Allowing very targetted CSS selectors, e.g.:
html[data-useragent*='Chrome/13.0'] .nav{
background:url(img/radial_grad.png) center bottom no-repeat;
}