Smartly Using Conditional Comments

For some time now I’ve had the standard way of using IE conditional comments to check for IE8 and IE7:

But thanks to the latest WordPress theme ‘twentyfourteen‘, I’ve found a much smarter way of being able to keep all your extra IE code in one CSS file:

Here, it simply checks first for IE7 or lower, then IE8, and adds a respective class, or it just uses a regular <html> tag. This way you can target  browsers directly in your core CSS file:

In all honesty, I rarely have to actually use conditional comments nowadays, but for the rare times that I do this is a much more elegant way of implementing them.

Kane Cheshire

Author: Kane Cheshire

I'm a software developer (and sort of designer) from Hertfordshire. I spend a lot of time learning, travelling and flying my drone. I made MacID. You can check out some of my favourite photographs from travelling at http://kane.codes. I'm also the creator and lover of Twicnic, an annual Twitter picnic event.

One thought on “Smartly Using Conditional Comments”

  1. As somebody pointed out, I haven’t mentioned that conditional comments won’t work in IE10 or 11. I’ve only targeted IE8 and lower here, if you need conditional comments for IE9 then you need to have a look at your CSS as IE9+ are pretty well standards compliant.

Leave a Reply

Your email address will not be published. Required fields are marked *