Browser Specific CSS
Posted: Thu Nov 20, 2008 2:40 am
Well, I just stumbled upon this and I find this to be a pretty good solutions to getting browser specific CSS without the need to using hacks. Best of all, I can do it for all kinds of browsers instead of just using the star hack which only works for IE. The original code uses JavaScript but I change it to use PHP instead. Here is what you will need to do:
1. Create a User Definded Tag with the following content (I'll call it user_agent):
Now, in the template, just use this tag as a class name. For example:
And there you have it. Any browser specific CSS can be done with:
When you think about, that was pretty simple.
1. Create a User Definded Tag with the following content (I'll call it user_agent):
Code: Select all
// The list of browsers
$browsers = array(
'Firefox' => ' Firefox/',
'Internet_Explorer' => ' MSIE ',
'WebKit' => ' AppleWebKit/', // Safari & Google Chrome
'Opera' => 'Opera/'
);
// Output the browser
foreach($browsers as $class_name => $search_key) {
if(is_numeric(strpos($_SERVER['HTTP_USER_AGENT'], $search_key))) {
echo $class_name;
return;
}
}
// If we made it here, the browser is not on the list
echo 'Unknown_Browser';
Code: Select all
...
</__body class="{user_agent}">
...
Code: Select all
/* Firefox specific CSS */
body.Firefox p { /* something */ }
/* Safari specific CSS */
body.WebKit p { /* something */ }