CSS problems with Internet Explorer
Every webdesigner have to face the truth: there is no code that works the same on all browsers. This site for instance deals with some serious issues concerning to the different ways Firefox and Internet Explorer reads CSS code, although Firefox meets the W3C standards and Internet Explorer doesn't. How to avoid problems with CSS and Internet Explorer then?
Javascript (eew!)
There are too many cons about use of Javascript because it's rendered client-side. It means the script runs when the client's already requested and is loading the website. It means the website might load differently for each browser. There are people also who disable Java Script on their browsers for security matters.
PHP (wee!)
This is a simple code for browser detection:
In this example, should you be using Netscape 6 then the server returns a particular code - otherwise, the code is different. If you want to go deeper, there's a bit more complex trick. This is an example - save a file named "browserdetect.php" on your directory with the following content:
-
<?php
-
/**
-
* $browser will contain one of the following values:
-
* 'iewin' : IE 4+ for Windows
-
* 'iemac' : IE 4 for Macintosh
-
* 'ie5mac' : IE 5 Macintosh
-
* 'nswin' : Netscape 4.x Windows
-
* 'nsunix' : Netscape 4.x Unix
-
* 'nsmac' : Netscape 4.x Mac
-
* 'ns6' : Netscape 6 / Mozilla
-
*/
-
-
function inAgent($agent) {
-
global $HTTP_USER_AGENT;
-
return !$notAgent;
-
}
-
-
( inAgent('MSIE 4') or inAgent('MSIE 5') ) {
-
( inAgent('Mac') )
-
$browser = inAgent('MSIE 5') ? 'ie5mac' : 'ie4mac';
-
elseif ( inAgent('Win') ) $browser = 'iewin';
-
} elseif ( !inAgent('MSIE') ) {
-
if ( inAgent('Mozilla/5') or inAgent('Mozilla/6') ) {
-
$browser = 'ns6';
-
} elseif ( inAgent('Mozilla/4') ) {
-
if ( inAgent('Mac') ) $browser = 'nsmac';
-
elseif ( inAgent('Win') ) $browser = 'nswin';
-
else $browser = 'nsunix';
-
}
-
} else $browser = "unknown";
-
-
?>
With this script on hand, server-side browser detection becomes quite simple. Put this into your page:
-
<?php
-
include(browserdetect.php); ?>
-
<?php if ($browser == 'ns6'): ?>
-
<!-- Netscape 6 specific code -->
-
<?php else: ?>
-
<!-- Code for other browsers -->
-
<?php endif; ?>
Within these lines now you may call the CSS external files written for the specific browser and job's done. Because in my humble opinion IE is the root of all evil, I'm using a slight modification of the code above.
-
<?php
-
function inAgent($agent) {
-
global $HTTP_USER_AGENT;
-
return !$notAgent; }
-
if ( inAgent('MSIE') ) { $browser = 'ie'; } ?>
-
<?php if ($browser == 'ie'): ?>
-
<!-- Code for Internet Explorer -->
-
<?php else: ?>
-
<!-- Code for other browsers -->
-
<?php endif; ?>









[...] - bookmarked by 6 members originally found by mtayla on 2008-10-30 CSS problems with Internet Explorer http://tech.nebulosabar.com/wordpress/css-problems-with-internet-explorer/ - bookmarked by 5 [...]