Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to deal with css browser compatibility?

Is it better to have a different CSS file for each user-agent or is it better to use CSS Hacks that only certain browsers can see?

like image 654
Jesse Shieh Avatar asked Apr 30 '09 20:04

Jesse Shieh


2 Answers

Neither.

The best is to write code that works in all browsers without the need of browser specific code or css hacks. It's of course not quite as easy to accomplish, which is why many people use the other methods.

The key is to avoid things that some browsers (very often Internet Explorer) has problems with. One such thing is to use padding rather than margin, because IE doesn't handle margin collapsing correctly.

Some methods that is in the border line of being hacks is using code that doesn't affect browsers that work correctly, but fixes problems for a specific browser. That could be things like specifying a height for an element that normally shouldn't need one, or specifying display:inline on a floating element.

The page Position is everything has examples of some bugs and suggested fixes. (Often the fix is some kind of hack, so you should of course also consider if you can avoid the problem altogether.)

like image 60
Guffa Avatar answered Nov 15 '22 05:11

Guffa


It's better to do neither.

A good css-reset and css that works the same cross-browser is a much better solution.

If your design absolutely precludes that, then (and only then) would I try hacks or IE conditional comments.

I haven't yet seen the need for mutliple css files (beyond a few IE6 corrections addressed via a conditional comment).

like image 20
18 revs, 10 users 77% Avatar answered Nov 15 '22 07:11

18 revs, 10 users 77%