This seems like such a smart, elegant, simple solution to targeting browsers with CSS - I’m surprised no one thought of it before.
Visit site...
I’m a digital product designer and developer in Seattle, WA. I currently work with nGen Works, and recently co-founded Lendle, a Kindle book sharing service.
Some of my clients include Facebook, Microsoft, Yahoo!, Copious, The New York Review of Books, The Lawrence Journal-World, and the University of Washington.
I’ve authored two books on web and interactive design and spoken at dozens of conferences around the world.
This seems like such a smart, elegant, simple solution to targeting browsers with CSS - I’m surprised no one thought of it before.
Visit site...
I saw that too and had the same reaction. Brilliant!
Then I got to thinking. Let’s face it, “targeting different browsers” is shorthand for “targeting IE6” most of the time. Most of the time, if you’re decently proficient at CSS, you don’t need a separate stylesheet for IE7. But I digress.
We’re talking about targeting IE.
And there’s already a very efficient, supported way of doing this, right? Conditional browser comments. And as I see it, conditional browser comments have two advantages.
1) No javascript needed! 2) Standards compliant browsers don’t have to parse CSS that is specific to only IE.
Anyway, I’m still thinking about this issue. I would definitely agree that on a large complex site with multiple stylesheets, this proposed solution would be more elegant (you could keep all CSS in one stylesheet). On the other hand, a large complex site is exactly the type of project where you don’t want to make these performance sacrifices.
So maybe it comes down to what matters more for the project: maintainability or performance. Thoughts?
I tend to agree with Jeremy - relying on scripting to class the body feels like overkill when 99% of the time all I want is to throw in some extra IE6 rules.
I like the idea that Paul Hammond put out a few days ago - wrap your BODY tag in conditional comments and add the “ie” classname that way, so as not to require multiple stylesheets.
If you first are going to use javascript of some kind I’d really prefer rather using IE7.js/IE8.js and just have one CSS for all the browsers.
Jeremy, Matthew: I totally agree that conditional comments is the best way to handle browser detection — if you’re trying to target IE. Lately, I’ve been needing to target Safari, Gecko, and Opera a fair deal, too, and this works quite well for that.