Is it possible to make Internet Explorer skip or avoid reading a line in the CSS stylesheet?
I'm mostly concerned with IE8, but interested in solutions for any version.
To prevent IE8 (and older) from reading the styles, simply use something in your selector that it doesn’t support and that all other browsers support.
For example, add :root
to your selector. Here’s an example: http://jsfiddle.net/mathias/kX6tR/
.foo { background: red; }
:root .foo { background: lime; }
:root
is supported in IE9 and all other browsers, therefore this is a safe CSS hack.
It is always better to avoid hacks altogether. The right thing to do in your case is re-define your CSS rule for IE in a separate stylesheet and include it after the main style file.
<link rel="stylesheet" href="nice_browsers.css" />
<!--[if IE]>
<link rel="stylesheet" href="dumb_ie.css" />
<![endif]-->
In addition normal browsers will not download the second file, so no extra HTTP request. And the main CSS file will validate (if you care about that - and you probably should)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With