Target IE9 Only via CSS

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 07:29:37

问题


Just wondering given these IE hacks in my bag of tricks

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

i.e. such as

body { 
    border:2px solid blue;
    border:2px solid yellow \\9;
    *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 ?


回答1:


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

<!--[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]--> 



回答2:


Terrible, but it should work:

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



回答3:


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

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

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



回答4:


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

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



回答5:


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:

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;}

Notes

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



来源:https://stackoverflow.com/questions/6654423/target-ie9-only-via-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!