IE 条件注释可以内联工作吗?
这应该有效吗?
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="/minify/css?f=ie8.css<!--[if lte IE 7]>,ie7.css<![endif]--><!--[if lte IE 6]>,ie6.css<![endif]-->" />
<![endif]-->
显然嵌套注释不起作用,那么这又如何呢?
<link rel="stylesheet" type="text/css" href="/minify/css?f=someotherfile.css<!--[if IE]>,ie8.css<![endif]--><!--[if lte IE 7]>,ie7.css<![endif]--><!--[if lte IE 6]>,ie6.css<![endif]-->" />
Should this work?
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="/minify/css?f=ie8.css<!--[if lte IE 7]>,ie7.css<![endif]--><!--[if lte IE 6]>,ie6.css<![endif]-->" />
<![endif]-->
Apparently nested comments don't work, so what about this?
<link rel="stylesheet" type="text/css" href="/minify/css?f=someotherfile.css<!--[if IE]>,ie8.css<![endif]--><!--[if lte IE 7]>,ie7.css<![endif]--><!--[if lte IE 6]>,ie6.css<![endif]-->" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,条件注释不是 HTML 之上的宏式处理;它们只能到达普通 HTML 注释可以到达的地方。评论不能进入标签内。
因此:(
您是否有足够的 IE 黑客规则来保证单独的样式表,即使对于 IE8 也是如此?该浏览器通常表现良好,只要它不处于兼容模式。如果您只有一些规则,这个技巧可能有用。)
No, conditional comments are not macro-style processing above HTML; they can only go where normal HTML comments can. Comments can't go inside tags.
Therefore:
(Do you have enough IE-hack rules that a separate stylesheet is warranted, even for IE8? That browser is generally pretty well behaved, as long as it's not in a compatibility mode. If you only have a few rules, this tip might be of use.)
它不会工作,因为你正在嵌套条件注释。
非 IE 浏览器将按照该站点语法突出显示的方式读取它。
要修复此问题,请从嵌套注释中删除结束
--
以将其隐藏在普通浏览器中。然后它应该可以正常工作。
例如:
It will not work, because you're nesting conditional comments.
A non-IE browser will read it the way this sites syntax highlighting reads it.
To fix it, remove the closing
--
from the nested comments to hide it from normal browsers.It should then work fine.
For example: