HTML – 即条件评论需要解释
发布时间:2020-12-14 18:46:45 所属栏目:资源 来源:网络整理
导读:以下代码用于可靠的跨浏览器IE版本检测 !--[if lt IE 7 ]body class="ie_6"![endif]--!--[if IE 7 ]body class="ie_7"![endif]--!--[if IE 8 ]body class="ie_8"![endif]--!--[if IE 9 ]body class="ie_9"![endif]--!--[if (gt IE 9)|!(IE)]!--body!--![endi
以下代码用于可靠的跨浏览器IE版本检测
<!--[if lt IE 7 ]><body class="ie_6"><![endif]--> <!--[if IE 7 ]><body class="ie_7"><![endif]--> <!--[if IE 8 ]><body class="ie_8"><![endif]--> <!--[if IE 9 ]><body class="ie_9"><![endif]--> <!--[if (gt IE 9)|!(IE)]><!--> <body> <!--<![endif]--> 我不明白的是,为什么它在起作用.为什么正常< body>没有覆盖< body class =“ie_9”>因为它只是一个普通的标签,所以应该被所有浏览器识别. 什么是魔术 <!--> <body> <!-- 解决方法
你可能想改变!(IE)到(!IE)
此外,“正常”< body>你正在谈论的标签是有条件的评论.事实上,它在不同的行上并不重要,它仍然在条件注释标记内,因此受到影响. IE的条件注释使用普通的HTML注释<! - - >所以“假”条件中的任何代码都只是被注释掉了; <! - < body class =“ie6”> – > IE然后在其中有自己的语法.因此,非IE浏览器只看到一个注释字符串,IE将其视为要执行的语句. 因此,只显示一个正文标记,并且只使用该标记. 更多解释 <!--[if (gt IE 9)|!(IE)]><!--> <body> <!--<![endif]--> 对于IE,这说: <if greater than ie9,or not ie> (ie conditional comment) <!--> (empty comment) (--> putting this here to stop SO ruining syntax highlighting :D) <body> <end if> (ie conditional comment) 如果你不明白为什么,请阅读从“IE工作的条件评论……”开始的段落. 与任何其他浏览器相同的块看起来像这样: <!--[if (gt IE 9)|!(IE)]><!--> (this is just one comment,containing the text "[if (gt IE 9)|!(IE)]><!") <body> <!--<![endif]--> (again,just one comment,containing "<![endif]") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |