HTML/条件注释 - 条件注释在浏览器中的行为是否符合预期?

发布于 2024-09-04 18:40:53 字数 590 浏览 10 评论 0原文

条件注释在浏览器中的表现是否符合预期?它们会导致渲染错误或其他问题吗?

此 CC 的格式/语法是否有任何错误?

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="718" height="227" id="swf">
    <param name="movie" value="images/swf.swf" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="images/swf.swf" width="718" height="227">
    <!--<![endif]-->
        <img src="images/alt.jpg" border="0" width="718" height="227">
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
</object>

Do conditional comments behave as expected across browsers? Can they cause rendering bugs or other issues?

Are there any errors in the formatting/syntax of this CC?

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="718" height="227" id="swf">
    <param name="movie" value="images/swf.swf" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="images/swf.swf" width="718" height="227">
    <!--<![endif]-->
        <img src="images/alt.jpg" border="0" width="718" height="227">
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
</object>

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

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

发布评论

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

评论(3

东风软 2024-09-11 18:40:53

条件 CSS 注释特定于 Windows 上的 IE。看看维基百科怎么说。

如果使用正确,它们将在其他浏览器中被解释为常规注释。这实际上取决于您如何使用它们。

您发布的示例将无法正常工作,因为您应该将整个条件包含在 HTML 注释中。

错误:

<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="images/swf.swf" width="718" height="227">
<!--<![endif]-->
    <img src="images/alt.jpg" border="0" width="718" height="227">
<!--[if !IE]>-->
</object>
<!--<![endif]-->

正确:

<!--[if !IE]>
<object type="application/x-shockwave-flash" data="images/swf.swf" width="718" height="227">
<![endif]-->
    <img src="images/alt.jpg" border="0" width="718" height="227">
<!--[if !IE]>
</object>
<![endif]-->

Conditional CSS comments are specific to IE on windows. See what wikipedia has to say.

If used correctly, they will be interpreted as regular comments in other browsers. It really depends on how you are using them.

The example you posted will not work correctly, as you are supposed to wrap the whole conditionals in an HTML comment.

Wrong:

<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="images/swf.swf" width="718" height="227">
<!--<![endif]-->
    <img src="images/alt.jpg" border="0" width="718" height="227">
<!--[if !IE]>-->
</object>
<!--<![endif]-->

Right:

<!--[if !IE]>
<object type="application/x-shockwave-flash" data="images/swf.swf" width="718" height="227">
<![endif]-->
    <img src="images/alt.jpg" border="0" width="718" height="227">
<!--[if !IE]>
</object>
<![endif]-->
断桥再见 2024-09-11 18:40:53

条件注释只是 HTML 注释,它们不会影响其他浏览器,因为它们被视为原样。只有 IE 会识别条件注释。

Conditional comments are just HTML comments, they cannot affect other browsers because they are treated as what they are. Only IE will recognize a conditional comment.

条件注释在浏览器中的表现是否符合预期?
根据我的经验,是的。 (仅如其他人所说的 IE)

它们会导致渲染错误或其他问题吗?
不,不是评论本身。其中的代码可能会导致渲染错误或其他问题,但在某种程度上,任何代码都可能导致渲染错误或其他问题。

此 CC 的格式/语法是否有任何错误?
我看不到,最简单的方法就是测试它。

Do conditional comments behave as expected across browsers?
From my experience, yes. (IE only as others have said)

Can they cause rendering bugs or other issues?
No, not the comments themselves. The code within, possibly, but to the same extent any code can cause rendering bugs or other issues.

Are there any errors in the formatting/syntax of this CC?
Not that I can see, easiest way is to test it.

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