Load different CSS depending on browser

Soldato
Joined
10 Apr 2006
Posts
7,853
Location
North West
Did a quick search on here to check if there was such a post but i dont think there is so....

Using CSS to style my website, it looks perfectly fine in IE7 and FF.
But in any IE previous versions the layout is different and i cant seem to adjust it without moving the DIVs around in FF, thus messing up my layout :(

I was looking into using JS to detect what browser is running and then load an appropriate CSS file.
I have it working for IE but not Firefox sadly :(

Part of the code:

if (browser == ''){
if (navigator.appName.indexOf('Microsoft') != -1)
browser = 'IE'
else if (navigator.appName.indexOf('?') != -1)
browser = '?'

In the question marks what do i put for Firefox, Netscape is just 'Netscape', and just Firefox or Mozilla don't work, so i was wondering what is meant to be put there.

If not , then is there a page anywhere showing IE 6 "hacks" to stop the layout being moved across as i've tried altering the padding and margins but it doesn't seem to work without pushing everything over in Firefox.

(oh and i checked the website in Safari and the background colour on the site is different to the colour in FF and IE, any reason why?)
 
Couldn't you do it like

if browser=IE6 then load hacked stylesheet
else
load normal stylesheet

?

As for Safari, it might be something to do with the silly colour profiles.
 
Whack this in your <head>
Code:
<!--[if IE<7]>
<link rel="stylesheet" href="..." />
<![endif]-->

You *shouldn't* need to differentiate between safari/fx/moz. Most should all be grand.
 
thanks, it is just having one between IE and FF/other browsers.
Just silly how you cant have one set of standard properties and attributes that work within all browsers, causes so many problems :(
 
IE7 beta's are out already, so you can get your standard stylesheet IE8 compatible, then just whack in a conditional stylesheet for IE<7
 
Back
Top Bottom