Better way of targetting IE in CSS
Hi everyone,
I just came across this article which explains a better way of targetting IE in your CSS. Basically, instead of using conditional comments to insert a different stylesheet, you insert an extra containing block with id="IEroot". This containing element is enclosed in conditional comments so it is only used in IE. You can even include multiple elements to target different versions of IE.
http://www.positioniseverything.net/articles/cc-plus.html
It's unfortunate that you have to include an extra div, but it's better than having a separate stylesheet that you always forget about, or using messy CSS hacks.
calculator posted this at 15:00 — 12th December 2007.
They have: 40 posts
Joined: Nov 2007
Hi Megan,
you only need to have the 'hacks' in the other stylesheet - I tend to have one with the box model fixes and that's it - roughly. It shouldn't be a problem then to keep it up to date.
Megan posted this at 16:41 — 12th December 2007.
She has: 11,421 posts
Joined: Jun 1999
You're referring to an IE only stylesheet served by conditional comments, right?
The problem comes when you forget that that stylesheet is there, or you don't know it's there because someone else did the design, and you can't figure out why things aren't working properly in IE. Or you make a change to your CSS without realizing that the same element is targetted in the IE-only CSS file. And there's no equivalent of Firebug for IE (or is there???) that shows you which rules are in which CSS file. Better to keep it all together if possible.
I usually find that I don't have to do a lot of IE-only CSS at all but this might be the best approach when it is necessary.
Megan
Connect with us on Facebook!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.