一种适用于所有 IE 版本的条件 CSS?
将所有条件 CSS 规则放在一个条件样式表中而不是为不同版本的 IE 制作多个样式表是一个好主意吗?
示例:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
all-ie-only.css 的内容:
selector {
color : green\9; /* IE8 and below */
*color : yellow; /* IE7 and below */
_color : orange; /* IE6 */
}
使用 IE 下划线/星号 hacks 请参阅:http://webstandardstips.com/2008/11/18/css-hacks-for-ie-only-style-rules/
Is it a good idea to put all conditional CSS rules in one conditional stylesheet instead of making multiple stylesheets for different versions of IE?
Example:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
Content of all-ie-only.css:
selector {
color : green\9; /* IE8 and below */
*color : yellow; /* IE7 and below */
_color : orange; /* IE6 */
}
Using IE underscore/asterisk hacks see: http://webstandardstips.com/2008/11/18/css-hacks-for-ie-only-style-rules/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在这种技术中看到的优点是您的服务器中只有一个样式表,这可能更容易维护。
缺点是用户需要下载整个文件,该文件可能大 3 倍,因此需要更多时间下载和处理。
除此之外,我认为没有其他问题。
The advantage I see in this technique is that you have just one style sheet in your server which may be easier to maintain.
The disadvantage is that users will need to download the whole file which may be 3 times bigger hence taking more time to download and to process.
Appart from that, I think there's no other issues with it.
是的,没关系。我认为这变成了文件必须容纳多少项目的问题。如果您只是覆盖 1/ 2/ 3 件事,那么单个文件更有意义。在某个任意点(10 件事? 100 行代码),我想说权衡会以另一种方式进行,并且维护这三个文件会更简单。
Yes, it's fine. I think it becomes a question of how many items the file has to hold. If you're just overriding 1/ 2/ 3 things, the single file makes much more sense. At some arbitrary point (10 things? 100 lines of code), I'd say the trade-off swings the other way and it's simpler to maintain the three files.
如果 IE 10 出现并使其中一些黑客行为失效怎么办?我认为这种方法违背了使用 IE 条件注释代替 hack 的目的,这更像是一种面向未来的实现。
另外,除了稍微容易维护和节省可忽略不计的 HTML 文件大小之外,还有什么优点吗?正如 LuckyShot 提到的,这对于 IE 用户来说已经是一种损害,因为他们必须下载更大的浏览器特定文件。
What if IE 10 comes along and invalidates some of these hacks? I think this approach defeats the purpose of using IE conditional comments in place of hacks, that being more of a future-proof implementation.
Plus is there any advantage, besides slightly easier maintenance, and negligible HTML file size savings? As LuckyShot mentioned, it's already a detriment for IE users which will have to download a larger browser-specific file.
对所有 IE 版本使用此功能是正确的。但是当你使用这个的时候你会发现,这不是
w3c valid
。一般来说,IE 会产生问题。Safari、Chrome 和 Firefox 都可以很好地运行。我认为对所有 IE 版本使用一种 Css 是更好的主意。this is right to use this for all IE Version. but when you use this then you will find that, this is not
w3c valid
. Generally IE create problem.Safari, Chrome , and Firefox will run these good.I think this is better idea to use one Css for all IE version.只要它有效并且有效,那么它是在 1 个文件还是 3 个文件中并不重要,这只是个人喜好。
就我个人而言,我更喜欢为每个 IE 版本提供单独的工作表(如果需要),因为我发现这样更容易组织。
就像我说的,如果它符合 W3C(上帝啊,我们不是很喜欢它们吗),那么一切都很好。
As long as it works and its valid, then it doesn't really matter whether its in 1 file or 3, its just personal preference.
Personally, I prefer to have a seperate sheet for each IE version (if needed), as I find it easier to organise.
Like I said, if its W3C complient (god, don't we just love them), then its all good.