Sarah K.

  • Norfolk, VA
Employee
PUBLIC PROFILE

CSS Condititionals are for more than just IE

Posted by Sarah Koszty on February 24, 2009, 6:50 AM EST
Sarah K. photo

While validating the CSS of one of my personal sites, the W3 CSS validator tool was being rather fussy about my -moz and -webkit styles. So after a few minutes considering a work-a-round it hit me, conditional browser tests were for more than just IE.

So if your like me, validation of your markup means alot more than a silly box you can place on your site saying that the W3 has verified you code as clean. No, it's a lot more than that. It means you care about the quality of your work, you put as much effort into the markup as you do the design, and it means you care about what happens when any user-agent enters your site (this includes search-bots). And, if you hand code like me, every time your able to validate a site that much quicker - your ego gets that little boost it needs.

So after playing around with rounded corners in CSS (which are supported by both FireFox and Safari), the CSS Validate tool hated my CSS. It not only hated my CSS, it told me that I was crazy for putting such non-sense into my stylesheet.

It's been pretty widely accepted to place IE6 and 7 workarounds into a separate stylesheet, and have that stylesheet called via a IE conditional statement in the header of you document. After thinking about my quandary for just a moment, it occurred to me that I take out all my FireFox and Safari specific styles and place those in a similar type conditional CSS - thus eliminating the CSS Validation from even seeing those styles.

So depending on the language your using (I currently use PHP for my personal projects), you could add a statement that looks like this;

<?php 
$agent = strtoupper($_SERVER['HTTP_USER_AGENT']);
$version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
if ($version == "Mozil") {
echo '<link rel="stylesheet" href="http://www.mysite.com/path/to/css/round.css" type="text/css" media="screen" />';
}
?>

And that's it. Not the most elegant code, but it was good enough to get this;

Valid CSS!

There are no comments

Sign in to add your comment.

Recent Posts

Friday Funnies
  Thanks http://kopozky.net/
read more
Inspirational Monday
Giving a whole new meaning to clean design; http://www.progressivered.com
read more
Friday Funnies
Thank you http://kopozky.net/
read more
7 Deadly Sins of Contract Web Design
It has taken many years at Hard-Knocks University in order for me to put this list together. I hope...
read more
Inspirational Monday
More nature inspired web design here.
read more
Friday Funnies
read more
Inspirational Monday
Now, I'm not a fan of the new Pepsi redesign, but this would be great product packaging....
read more
Friday Funnies
read more
Inspiration Monday
Amazing UI and information Display. Simple, clean, orginial and fresh. A must to visit for those who...
read more
Friday Funnies
Every designers nightmare ... courtsey of http://www.kopozky.net/the-life-and-death-of-design  
read more

Go to blog