views:

65

answers:

6

I am getting rid of browser compatibilty issues.

so i come up with idea to load the only css according to browser.

So say if user uses IE then only styleIE.css get loaded if firefox styleFF get loaded and so on.

my question is it correct method if not what care should taken to avoid this compatibilty issues. because when i solve issues for IE then it opens the new issue in a my stable version of FF

A: 

Yes, many websites do just that.

mcandre
+5  A: 

That is done frequently although you probably want to use a general CSS file with the shared styles and combine it with the browser dependent CSS file.

But in fact most CSS problems with different browsers can be solved without this trick and by just using the correct markup and styles...

Koen
@Koen: I'm assuming you haven't seen much of IE6? It's now sloooowly dying out, but no - you can't solve most CSS problems in IE6 by being correct, for it is an abomination that insists on its broken pseudostandards. (IE7 and above play much nicer, thankfully)
Piskvor
@koen:- so what you suggest differnt css or correct markup for better maintainanace?
Salil
@Salil: you should always try to get as little exceptions to your standard layout rules as possible. That makes maintenance easier. Obviously you can't get that 100% right (e.g. IE6 can be a pain)...
Koen
not only IE6 i get rid of All IE versions
Salil
Getting rid of all IE is not advisable, there's still a large market share of people using IE 6, and a larger share using any version of IE.
Alex Larzelere
+3  A: 

Usually it's enough to create a stylesheet that looks well in normal browsers, and then make a IE-only supplemental stylesheet that fixes the incompatibilities and include it through conditional comments (although IE8+ is kind of OK and IE7 usually works):

<!--[if IE]>
    <link rel="stylesheet" href="/ie_sheet.css" type="text/css">
<![endif]-->

Since IE6 is a horrible monster from the dawn of time, which needs its own specific hacks, you can include a different stylesheet for IE6 (and lower) and IE7 (and higher; not really needed most of the time):

<!--[if lte IE 6]>
    <link rel="stylesheet" href="/ie6_sheet.css" type="text/css">
<![endif]-->
<!--[if gt IE 6]>
    <link rel="stylesheet" href="/ie_newer_sheet.css" type="text/css">
<![endif]-->

Other browsers parse these as HTML comments and ignore them.

See also: a more detailed discussion of conditional comments.

Piskvor
As you say, IE8+ is kind of OK and from my experience don't need the IE7-specific stylesheet. Worse, it can affect the rendering. Otherwise +1 to your answer
Felipe Alsacreations
+1  A: 

I use a reset stylesheet, a normal stylesheet (i.e., for all standards-compliant browsers) then IE-specific stylesheets that reference the various versions of IE. The IE stylesheets only cover the items that IE has trouble with. I use the Microsoft conditional comments for including those stylesheets, so they are not read by other browsers.

Robusto
A: 

That works just fine, the only thing to keep in mind is that, everytime your user loads a page, now the browser has to run through all the conditionals. So as long as it's not excessive (one check for each version of every major browser), nobody will notice.

Now making changes to the css if you've got even just 3 or 4 versions will be a bit of a pain, but everything has it's cost.

Alex Larzelere
If you mean "conditional comments", those are only parsed by IE, all other browsers see them as normal HTML comments and ignore them. Also, in my experience, it's usually sufficient to have a conditional stylesheet for IE6, in addition to the global stylesheet.
Piskvor
Still the additional weight of all those comments cost memory. I agree though that having a global stylesheet and a condiitonal style sheet are the way to go. Makes you a better designer if you can not only handle all of IE6s quirks, and you get the added bonus of learning more about how CSS actually functions.
Alex Larzelere
A: 

It's not morally reprehensible, but it is less than ideal.
You can solve cross-browser compatibility issues by learning a little more about what is going on.

http://hsivonen.iki.fi/doctype/
http://validator.w3.org/
http://jigsaw.w3.org/css-validator/
http://www.positioniseverything.net/explorer.html

reisio