Html 仅通过 CSS 定位 IE9

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6654423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:30:10  来源:igfitidea点击:

Target IE9 Only via CSS

htmlcssinternet-explorer-9stylesheetcss-hack

提问by Tim

Just wondering given these IE hacks in my bag of tricks

只是想知道我的技巧包中的这些 IE 黑客

"" - for IE8 and below.
"*" - for IE7 and below.
"_" - for IE6.

i.e. such as

即例如

body { 
    border:2px solid blue;
    border:2px solid yellow ;
    *border:2px solid green;
    _border:2px solid orange;
}

Whether anyone has such a hack for IE9 ? i.e. I'm trying to target IE9 only via CSS ?

是否有人对 IE9 有这样的破解?即我试图仅通过 CSS 定位 IE9 ?

回答by Jeffrey Karbowski

Terrible, but it should work:

可怕,但它应该工作:

body { 
    border:2px solid blue;
    border:2px solid yellow ;
    *border:2px solid green;
    _border:2px solid orange;
}
body:nth-child(n) {border:1px solid purple ; /*Should target IE9 only - not fully tested.*/}

回答by meder omuraliev

I suggest using condcomsto feed an IE9 css file or have a conditional html class, similar to:

我建议使用condcoms来提供 IE9 css 文件或有一个条件 html 类,类似于:

<!--[if lt IE 7]> <html lang="en-us" class="no-js ie6"> <![endif]--> 
<!--[if IE 7]>    <html lang="en-us" class="no-js ie7"> <![endif]--> 
<!--[if IE 8]>    <html lang="en-us" class="no-js ie8"> <![endif]--> 
<!--[if gt IE 8]><!--> <html lang="en-us" class="no-js"> <!--<![endif]--> 

回答by Radu

IE9 is pretty standards compliant. You shouldn't need to hack it.

IE9 非常符合标准。你不应该需要破解它。

Also, you should be using IE conditional commentsto load different styles. For IE 9 you would do:

此外,您应该使用IE 条件注释来加载不同的样式。对于 IE 9,你会这样做:

<!--[if IE 9]>
    <!-- conditional content goes here -->
<![endif]-->

回答by Val Entin

At this adress : http://www.impressivewebs.com/ie10-css-hacks/I found a media query specific for IE10 only (and below) :

在这个地址:http: //www.impressivewebs.com/ie10-css-hacks/我发现了一个仅针对 IE10(及以下)的媒体查询:

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {  
   /* IE10-specific styles go here */  
}

回答by Beejor

As noted in some of the comments, there are times when conditional HTML won't work for a specific situation, especially if you're unable to modify the page code itself. So here's a workaround:

正如一些评论中所指出的,有时条件 HTML 不适用于特定情况,尤其是当您无法修改页面代码本身时。所以这里有一个解决方法:

Base Style

基本样式

.test{color:red;}

Browser-Specific Overrides

特定于浏览器的覆盖

IE < 8: html >/**/body .test { color: green; }
IE 9: :root .test{color:green \ ;}
IE 8 and 9: .test{color:green \ ;}
IE 9 and Opera :root .test {color: green\0;}

IE < 8:html >/**/body .test { color: green; }
IE 9::root .test{color:green \ ;}
IE 8 和 9:.test{color:green \ ;}
IE 9 和 Opera:root .test {color: green\0;}

Notes

笔记

The above won't work for backgroundor font-*, and any \0or \9hacks are generally unstable. For a complete list of CSS hacks, see http://mynthon.net/howto/-/webdev/CSS-big-list-of-css-hacks.txt.

以上不适用于backgroundor font-*,并且 any \0or \9hacks 通常不稳定。有关 CSS hack 的完整列表,请参阅http://mynthon.net/howto/-/webdev/CSS-big-list-of-css-hacks.txt