鉴于线程的发展,我更新了以下内容:
IE 6
* html .ie6 {property:value;}
要么
.ie6 { _property:value;}
IE 7
*+html .ie7 {property:value;}
要么
*:first-child+html .ie7 {property:value;}
IE 6和7
@media screen\9 {
.ie67 {property:value;}
}
要么
.ie67 { *property:value;}
要么
.ie67 { #property:value;}
IE 6、7和8
@media \0screen\,screen\9 {
.ie678 {property:value;}
}
IE 8
html>/**/body .ie8 {property:value;}
要么
@media \0screen {
.ie8 {property:value;}
}
仅限IE 8标准模式
.ie8 { property /*\**/: value\9 }
IE 8,9和10
@media screen\0 {
.ie8910 {property:value;}
}
仅限IE 9
@media screen and (min-width:0\0) and (min-resolution: .001dpcm) {
// IE9 CSS
.ie9{property:value;}
}
IE 9以上
@media screen and (min-width:0\0) and (min-resolution: +72dpi) {
// IE9+ CSS
.ie9up{property:value;}
}
IE 9和10
@media screen and (min-width:0) {
.ie910{property:value;}
}
仅限IE 10
_:-ms-lang(x), .ie10 { property:value\9; }
IE 10以上
_:-ms-lang(x), .ie10up { property:value; }
要么
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.ie10up{property:value;}
}
使用方式-ms-high-contrast
意味着不会将MS Edge作为目标,因为Edge不支持-ms-high-contrast
。
IE 11
_:-ms-fullscreen, :root .ie11up { property:value; }
Javascript替代品
Modernizr在页面加载时快速运行以检测功能。然后使用结果创建一个JavaScript对象,并将类添加到html元素
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':'');
在html
元素中添加(例如)以下内容:
data-useragent='Mozilla/5.0 (compatible; MSIE 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'
允许目标明确的CSS选择器,例如:
html[data-useragent*='Chrome/13.0'] .nav{
background:url(img/radial_grad.png) center bottom no-repeat;
}
脚注
如果可能的话,找出并解决所有问题,避免被黑客入侵。支持渐进增强和正常降级。但是,这并非总是可以实现的“理想世界”场景,因此,上述内容应有助于提供一些不错的选择。
出处/必读