开发者

is it ok to use different css files for different browsers and load it accordingly

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 sty开发者_如何学编程leFF 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


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...


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.


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.


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


Yes, many websites do just that.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜