User Agent CSS

,

For a few weeks now I've been working on the idea of being able to easily send different CSS styles to different browsers. My original need was to send a different display property to the Safari and Konqueror browsers to work around a bug. The end result was my development of a Perl script available on my web site:

http://www.scss.com.au/family/andrew/webdesign/uacss/

My timing of this is rather interesting. The IEBlog has recently posted The demise of CSS hacks. It's becoming more and more obvious that the current widespread use of CSS hacks is not sustainable.

Just a minute while I get up a little higher on my soapbox...

I've always thought that CSS hacks were a bad idea - especially those that rely on parser bugs or other unintended and undocumented behaviour. They were a Pandora's box that should never have been opened. Now we have a whole bunch of people bitching and moaning that Microsoft are fixing their browser hacks without fixing the CSS bugs that had people looking for the hacks in the first place.

I have no sympathy for those people. Maybe I'm being a bit harsh, but I defy anyone to honestly say that designing your software/website so that it relies on bugs for correct operation is a good idea.

Anyway, apart from bug characteristics, there are a few options still available:
  1. User agent sniffing (either server- or client-side)
  2. Conditional comments (only for IE)
It's not a big list! My script does user agent sniffing. User agent sniffing has a reputation for being unreliable, however, server-side scripts have no other options. Done properly, it's really not that bad, it's when you start making assumptions, such as that the presence of "MSIE" in the user agent string says something about ActiveX support (it doesn't), that you run into trouble.

My script is not immune to that sort of trouble either, but it doesn't come from the script itself, rather it comes from lazy and irresponsible web designers who might feel tempted to do:
body {
  -uacss-iewin-display: none;
}
There's not much that can be done about that! Ultimately, my script is just tool. It's all in how you use it. I've included some usage guidelines on my web page. It's my hope that people may find my script useful.

Dual screensFollowing the herd

Comments

Rijk Friday, October 14, 2005 1:30:51 PM

I think this is looking really good. For those with reasonable server access, I can't think of a better way to do the dirty thing.

Maybe you could add even more emphasis on the guideline that the 'normal' value should be targeted at user agents that correctly implement the CSS spec - this is so crucial for forward compatability!

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

February 2012
S M T W T F S
January 2012March 2012
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29