Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 479
Gaelen Avatar asked Feb 02 '12 21:02

Gaelen


People also ask

Can div be in head tag?

You can put divs in < header > as of HTML5, but never in < head >.

Can you put div inside a Tbody?

You can't put a div directly inside a table but you can put div inside td or th element. Save this answer.

Can I put a div inside a script?

You can add <script></script> inside a DIV tag. Just check on w3c, it is valid HTML. Save this answer.


2 Answers

  • 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>.
like image 106
josh3736 Avatar answered Sep 22 '22 22:09

josh3736


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]-->
like image 38
Dominic Green Avatar answered Sep 22 '22 22:09

Dominic Green