IE Conditional Comments and Chrome/Firefox

只愿长相守 提交于 2019-12-02 23:40:39

Conditional comments are a Microsoft IE-specific rule, and they are not part of any standard. If you check the structure of a conditional comment:

<!--[if gt IE 7]>
Here is some code.
<![endif]-->

As its name would imply, it is all just a big comment <!-- comment -->. IE checks comments for conditions such as these which, again, do not comply with HTML standards.

To create code which doesn't render in IE, but does render in other browsers, you use the following conditional:

<!--[if !IE]> -->
This will be rendered by anything but IE.
<!-- <![endif]-->

See how the conditions are enclosed in closed comments? That's why that is rendered in normal browsers, while IE checks for the conditional, and decides to omit everything up until the endif.

EDIT

If you want to add another condition, and keep rendering the code on non-IE browsers, you could use the following workaround:

<!--[if gt IE 7]> <!-- -->
Here is some code for anything but IE 7 and below.
<!-- <![endif]-->

Note I had to use open the comment again to prevent IE from rendering --> before the code. Other browsers will still consider it part of the comment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!