Apply css styles only to ie9

2019-09-07 06:18发布

问题:

im my website i have a file (ie.css) to correct css problems of the ie. However, now i have a litte problem. Some default styles of the website are good on ie8 and not on ie9.

So, i would like to apply the follow css code inside the file "ie.css" only to the ie version 9, is that possible?

.ngg-galleryoverview {
    overflow: hidden;
    margin-top: 10px;
    width: 100%;
    clear:both; 
    display:block !important;
    /*border: 2px solid #ADE132;*/
    /*margin-left: 10px;*/
    margin-left: 2%;
}

.ngg-gallery-thumbnail {
    float: left;
    margin-right: 3%;
    /*margin-right: 10px;*/
    text-align: center;
    /*border: 2px solid #ADE132; */
    height: 430%;
    width: 430%;
}

回答1:

What you're looking for is conditional comments:

<!--[if IE 9]>
<style type="text/css">
  IE specific CSS rules go here
</style>
<![endif]-->


回答2:

The best way to do this is to set a body class only for IE9 and when you want to modify your css it will begin wit that class in front any other html tag or class. This will guarantee that your css is w3c compliant.

Here's the code for that:

<!--[if IE 9 ]>    <body class="ie9"> <![endif]-->


回答3:

Use IE conditional comments:

<!-- [if ie 9]>
 CSS that you want to be IE only
<![endif]>-->


回答4:

Try in css like

:root .classname{ color:pink \0/IE9; } /* IE9 */

OR write in head tag

<!--[if IE 9]>
<style>
Special instructions for IE 9 here
</style>

<![endif]-->