-1

I am working on a site where I need to load a conditional stylesheet for every version of IE(up to 11). I realize that conditional comments are not supported in IE10+ so I will need another way of conditionally loading this stylesheet. The other thing is that I do not want this stylesheet to load on Microsoft Edge, only on Internet Explorer.

What would be the best way to go about this?

To clarify, I am attempting to target all versions of IE, not just 10.

user13286
  • 3,027
  • 9
  • 45
  • 100
  • Possible duplicate of [Are There Specific CSS Selectors Targeting IE10?](http://stackoverflow.com/questions/7321093/are-there-specific-css-selectors-targeting-ie10) – Peter O. Mar 17 '16 at 17:21
  • That is not a duplicate, I am attempting to target ALL versions of IE, not just 10. – user13286 Mar 17 '16 at 17:30
  • You can use CSS Hacks, take a look [here](http://browserhacks.com/#ie) – dippas Mar 17 '16 at 17:33

2 Answers2

0

you can use conditional comments up to and with ie9, you can use conditional compilation for ie10, as for ie11 and edge, ua sniff is the route i would go, knowing full well its not a solid approach and will inevitably break something.

albert
  • 8,112
  • 3
  • 47
  • 63
0

I ended up using PHP to add a class to the body if the user was using IE since it uses the least amount of code:

if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false))

Source

user13286
  • 3,027
  • 9
  • 45
  • 100