我正在使用 HTML5 Boilerplate,直到现在我开始使用 Selectivizr。由于某种我不明白的原因,IE8 产生了 Javascript 错误。
经过一些测试后,我注意到当我停止使用条件浏览器注释(在样板中)时,错误消失了,该注释根据您使用的浏览器向 html
添加类:
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
正如我所说,当我删除上面的代码并将其替换为
一切正常。
由于我不想完全删除条件注释(它们帮助我编写浏览器特定的 css),所以我想做同样的事情,但我不会将其应用于 html
我会为
:
<!--[if lt IE 7]> <body class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <body class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <body class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <body class="no-js" lang="en"> <!--<![endif]-->
一切似乎都正常,但由于我是新手,我只想验证一下这个解决方法是否可以?或者有什么缺点吗?
还有一个题外话:当用户使用 Firefox 或 Chrome 访问网站时,将“使用”什么 body
?我想它会在没有类的情况下“使用”body
?
我的逻辑会告诉我写另一个条件注释,以确保对所有其他浏览器“使用”body
,但是在官方样板模板中不存在这样的注释,因此我想它不需要。为什么不呢?
I am using the HTML5 Boilerplate and never had a problem with it until now, when I have started using Selectivizr. For some reason, which I dont understand, IE8 produced a Javascript error.
After some testing, I noticed that the error was gone when I stopped using the conditional browser comments (in the Boilerplate) that add a class to html
depending on the browser you are using:
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
As I said, when I remove the code above and replace it with <html>
everything works fine.
Since I dont want to remove the conditional comments completely (they help me to write browser specific css), I thought of doing the same, but instead of applying it to html
I will do it for the <body>
:
<!--[if lt IE 7]> <body class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <body class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <body class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <body class="no-js" lang="en"> <!--<![endif]-->
Everything seems to work okay, but since I am a newbie, I would just like to verify that this workaround is okay? Or is there a downside?
And one more question offtopic: When a user visits the site with Firefox or Chrome, what body
will be "used"? I guess it will "use" body
without a class?
My logic would tell me to write another conditional comment, to make sure to "use" body
for all other browsers, however in the official Boilerplate template no such comment exists and therefor I guess its not needed... Why not?
发布评论
评论(1)
实际上,我们最初将它们放在
> 上。标签。 :)
我们移动它们有两个小原因:
将 body 元素用于自己的类。您可以将类移动到
,不会有太大问题。您还可以将
lang=en
留在 HTML 元素上,以进行清理。更多详情请参见:https://github.com/h5bp/html5-boilerplate/issues/44
We actually originally had them on the
<body
> tag. :)We moved them for two small reasons:
You can move the classes to
<body>
without much problem. You can also leavelang=en
on the HTML element, cleaning things up.More deets here: https://github.com/h5bp/html5-boilerplate/issues/44