Jobs!
Meetups by TopicMeetups by CityStart a MeetupWhat's Meetup
Home > All Topics > Internet & Technology > Web Design Meetups Everywhere > The Prescott Web Design Meetup Group
Organizer:

Join The Prescott Web Design Meetup Group!

We'll never share your email address without your permission. Already a Meetup member? Sign in.

Messages

Learning Cascading Style Sheets (CSS)

Message Board › Learning Cascading Style Sheets (CSS)

Nancy Timper
swami12
Prescott, AZ
5th Post

Hi Derek,

Your fixes all work great. I misunderstood at first that your second suggestion would work in all browsers when I think what you were offering was a fix for IE5 (Mac) only.

SO I am going to use your first suggestion which did the trick everywhere else.

It seems like there are secrets to CSS that only experience teaches! Its hard enough to understand without that, but help like yours is invaluable. Thanks Again!


nancy

Kerry Wilson
kwdesigner
Group Organizer
Prescott, AZ
12th Post

Sometimes you cannot overcome all the differences between the major browsers and the best thing to do is use a detection script to load a different css file based on what browser the person is using.

Here is an example (using PHP):

<?

function browser_detection( $which_test ) {

// initialize the variables
$browser = '';
$dom_browser = '';

// set to lower case to avoid errors, check to see if http_user_agent is set
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';

// run through the main browser possibilities, assign them to the main $browser variable
if (stristr($navigator_user_agent, "opera"))
{
$browser = 'opera';
$dom_browser = true;
}

elseif (stristr($navigator_user_agent, "msie 4"))
{
$browser = 'msie4';
$dom_browser = false;
}

elseif (stristr($navigator_user_agent, "msie"))
{
$browser = 'msie';
$dom_browser = true;
}

elseif ((stristr($navigator_user_agent, "konqueror")) || (stristr($navigator_user_agent, "safari")))
{
$browser = 'safari';
$dom_browser = true;
}

elseif (stristr($navigator_user_agent, "gecko"))
{
$browser = 'mozilla';
$dom_browser = true;
}

elseif (stristr($navigator_user_agent, "mozilla/4"))
{
$browser = 'ns4';
$dom_browser = false;
}

else
{
$dom_browser = false;
$browser = false;
}

// return the test result you want
if ( $which_test == 'browser' )
{
return $browser;
}
elseif ( $which_test == 'dom' )
{
return $dom_browser;
// note: $dom_browser is a boolean value, true/false, so you can just test if
// it's true or not.
}
}



$user_browser = browser_detection('browser');

if ( $user_browser == 'msie' )
{
echo "<link rel=\"stylesheet\" href=\"template_css.css\" type=\"text/css\"/>" ;
}
else if ( $user_browser == 'ns4' || $user_browser == 'mozilla')
{
echo "<link rel=\"stylesheet\" href=\"netscape.css\" type=\"text/css\"/>" ;
}
else if ( $user_browser == 'opera' )

{
echo "<link rel=\"stylesheet\" href=\"opera.css\" type=\"text/css\"/>" ;
}

else if ( $user_browser == 'safari' )

{
echo "<link rel=\"stylesheet\" href=\"safari.css\" type=\"text/css\"/>" ;
}
?>

Powered by mvnForum