是否可以为不同的浏览器使用不同的css文件并相应地加载它

发布于 2024-09-07 11:02:49 字数 206 浏览 2 评论 0原文

我正在摆脱浏览器兼容性问题。

所以我想出了根据浏览器加载唯一的CSS的想法。

所以说,如果用户使用 IE,那么只有 styleIE.css 会被加载,如果 firefox styleFF 会被加载,依此类推。

我的问题是,如果不是正确的方法,应该采取什么措施来避免这种兼容性问题。 因为当我解决 IE 的问题时,它会在我的 FF 稳定版本中打开新问题

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

指尖凝香 2024-09-14 11:02:49

尽管您可能想要使用具有共享样式的通用 CSS 文件并将其与依赖于浏览器的 CSS 文件结合起来,但这种做法经常被执行。

但事实上,不同浏览器的大多数 CSS 问题都可以解决,无需这个技巧,只需使用正确的标记和样式......

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

羁客 2024-09-14 11:02:49

补充样式表来修复不兼容性并通过条件注释包含它(尽管 IE8+ 还可以,IE7 通常也可以):

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

通常创建一个在普通浏览器中看起来很好的样式表就足够了,然后制作一个仅适用于 IE的 可怕的怪物从一开始就需要它自己的特定黑客,您可以为 IE6(及更低版本)和 IE7(及更高版本;大多数时间并不真正需要)包含不同的样式表:

<!--[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]-->

其他浏览器将这些解析为 HTML 注释和忽略他们。

另请参阅:条件注释的更详细讨论。

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.

浅唱ヾ落雨殇 2024-09-14 11:02:49

我使用重置样式表、普通样式表(即,适用于所有符合标准的浏览器),然后使用引用各个版本 IE 的 IE 特定样式表。 IE 样式表仅涵盖 IE 有问题的项目。我使用 Microsoft 条件评论用于包含这些样式表,这样其他浏览器就不会读取它们。

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.

诗酒趁年少 2024-09-14 11:02:49

这在道德上不应受到谴责,但它不太理想。
您可以通过更多地了解正在发生的事情来解决跨浏览器兼容性问题。

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

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

鯉魚旗 2024-09-14 11:02:49

是的,许多网站就是这么做的。

Yes, many websites do just that.

战皆罪 2024-09-14 11:02:49

这工作得很好,唯一要记住的是,每次用户加载页面时,浏览器都必须运行所有条件。因此,只要不过分(对每个主要浏览器的每个版本进行一次检查),就没有人会注意到。

现在,如果你只有 3 或 4 个版本,那么对 CSS 进行更改就会有点痛苦,但一切都是有代价的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文