Is it bad to put <div> elements within the <head> tags?

…衆ロ難τιáo~ 提交于 2019-12-10 03:26:24

问题


I want to use conditional comments to make a DIV appear ONLY in browsers with IE7 or older, like this:

<!--[if lt IE 7]>

<div id="browsernotice">
<p>You are using IE7 or less</p>
</div>

<![endif]-->

As far as I understand, conditional comments only work in the header.

Is this bad?

Should I rather use conditional comments to instert a stylesheet that makes an invisible DIV visibility:visible?


回答1:


The best way is to keep the content as is in the document body but instead apply a style sheet for ie that hides the div.

with css

    #browsernotice {
       display:none;
}

And call it with a conditional statement

<!--[if lt IE 7]>
<link href="ie7.css" type="text/css" rel="stylesheet">
<![endif]-->



回答2:


  • Yes, it is bad to put a <div> in your <head>. It's not valid.
  • Conditional comments do work anywhere in the document (where did you get the idea they don't?), so just put your code at the top of your <body>.


来源:https://stackoverflow.com/questions/9120554/is-it-bad-to-put-div-elements-within-the-head-tags

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