It sounds like your problem could be solved in some other way than browser-conditional styles, please try that first, but in any case:
For IE 10 and 11, you can use this:
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}
Note though, that it will recognize both IE 10 and 11.
source: https://philipnewcomer.net/2014/04/target-internet-explorer-10-11-css/
You may also want to take a look at this:
http://marxo.me/target-ie-in-css/
For IE 9 and lower, you can use this:
You create a separate stylesheet for that, and then you use this to include that in your HTML.
source: https://css-tricks.com/how-to-create-an-ie-only-stylesheet/
For example, if you wanted to target IE 7, you would do this. You can just change the version number to what you will.
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css">
<![endif]-->
And then you can also target lower or higher versions than a specific version:
Lower than IE 8 and IE 8:
<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->
Higher than IE 8:
<!--[if gt IE 8]>
<link rel="stylesheet" type="text/css" href="ie6-and-up.css" />
<![endif]-->
Note that you can use lt
, lte
, gt
or gte
.
but the problem is I don't know why that strange behavior happened in IE only. – Yasmin Aug 25 '15 at 09:27