May 7, 201016 yr Hello, Whats the best way to load a style sheet for a specific browser, Example, if a user was to use IE, the website would load the stylesheet for IE, if they was to use firefox it would load a style sheet for firefox.
May 7, 201016 yr It's easier if you code the link for all browsers except IE first and then code conditional comment(s) for versions of IE afterwards in the head section. <link rel="stylesheet" href="style1.css" media="all" type="text/css"> <!--[if ie 6]> <link rel="stylesheet" href="ie6.css" media="all" type="text/css"> <![endif]--> If you want to target a specific browser like Firefox but not Safari,IE, etc. that's more difficult and usually shouldn't be necessary. I think you can use javascript to sniff for Firefox and then feed a different stylesheet, but I've never needed to do it.
May 7, 201016 yr Author Thanks mate, So if the user has IE6 the code above will load the IE6 Stylesheet instead of the default one?
May 7, 201016 yr Thanks mate, So if the user has IE6 the code above will load the IE6 Stylesheet instead of the default one? Not "instead". It will load in the main one AND then the IE6 one if the visitor is on IE6. In your IE stylesheet you only need styles for the borken elements - not the full stylesheet again
May 7, 201016 yr Yes. Browsers process from the top down, so a browser will process all the main stylesheet styles and then, if it's the stated IE version in the conditional comment, will overwrite with the styles for the IE version. You can have several conditional comments for different IE versions or just one for all IE versions. Usually you only need one for "lt IE 7" which means all IE versions less than IE7. http://www.javascriptkit.com/howto/cc2.shtml
May 7, 201016 yr Author Thank you very much guys for all your help, I actual forgot the browser processes from top the bottom, i dont understand why IE, Firefox and any other browser dont just come togeather and make it work for everyone instead of causing webdesigners problems all the time... P*sses me of and its ALWAYS something to do with IE
Create an account or sign in to comment