HTML5 Boilerplate IE 条件 IE8 说明

标签 html

我一直在寻找解释为什么 HTML5 Boilerplate 中 IE 的 html 标签条件有这一部分:

<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

我问这个问题只是为了让我了解这是如何运作的。我理解上面的条件,但是为什么这个与上面的不同?我不明白这种情况与上面的情况相比有何作用。

预先感谢您帮助我理解我将要使用的东西。

最佳答案

基本上,最后一部分用于 IE 9 及更高版本以及所有其他浏览器。然而,语法更短并且并不像它可能的那样直接,因为 HTML Boilerplate 非常关注优化。

我找到了解释它的文章,我建议您阅读全文:

http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

Here's my proposed solution:

<!--[if lt IE 7]>      <html class="ie6"> <![endif]-->
<!--[if IE 7]>         <html class="ie7"> <![endif]-->
<!--[if IE 8]>         <html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html>         <!--<![endif]-->

由于您可以在文章中读到的问题,这实际上是后来更新的。

显然,奇怪的语法的一部分与 Dreamweaver(!) 错误有关。以下是摘录:

Here is the new recommendation, and the one that's in use in the HTML5 Boilerplate.

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->

基本上,最后一行是说“如果 IE9+ 或不是 IE 则执行此操作”。下面的一些要点与您的问题没有直接关系,但无论如何我都会将它们包括在内。

Why?

  • This fixes a file blocking issue discovered by Stoyan Stefanov and Markus Leptien.
  • It avoids an empty comment that also fixes the above issue.
  • CMSes like WordPress and Drupal use the body class more heavily.
  • This makes integrating there a touch simpler It doesn't validate in html4 but is fine in html5. Deal with it.
  • It plays nicely with a technique to kick off your page-specific javascript based on your markup.
  • It uses the same element as Modernizr (and Dojo). That feels nice.
  • I left an empty class in there because you'll probably be putting a no-js in there or something else. If not, delete.
  • Also if the extra comments around that last tag look weird to you, blame Dreamweaver, which chokes on normal !IE conditional comments.

有关此问题的更多讨论:https://github.com/h5bp/html5-boilerplate/issues/425/#

关于HTML5 Boilerplate IE 条件 IE8 说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13404414/

相关文章:

php - 使用 PHP 和 MySQL 单击产品图像显示产品详细信息

html - 如何将多个按钮与响应式设计内联?

html - 停止突出显示 HTML 文本

jquery - 添加div后图像不断向下移动

javascript - HTML5 : element <group>

jquery - 响应式 iframe 轮播模式?

javascript - 在 PHP 中使用 javascript 刷新 div

html - 基本上,我想要两列包含文本和图像,但第二列是倒置的

javascript - 如何基本上添加两个 <Button> 标签的值

Python:使用 bs4 和 RegEx 仅解析来自 HTML 的文本