Placing a DIV in <head>
Asked Answered
E

3

2

I am going to install a banner in the website, which target to run of the entire website. The banner is set to position:fixed & bottom:0px so it will be a floating banner at the bottom.

My website structure is a common header file, with many body files which corresponding to different pages.

If I put this DIV in the common header file (the <head> section), it will automatically achieve the result. However, if I put this DIV in the body files instead (the <body> section), I have to open the body documents one by one and add the DIV for so many times.

I see that on the Internet, people always don't recommend to put a DIV in <head> section. May I know the reason? Is there any harm? As I have tested by myself, it seems there's not much difference.

Eurythermal answered 28/9, 2014 at 19:9 Comment(2)
What do the header file contain? Only the <head> portion of your page, or something else?Estivate
The title says <head>, description says header file in the beginning and section in the end..!Sundaysundberg
W
9

If I understand your question, you want to know the reason people say not to put div in < head > tags.

Well, the reason is that by doing that, the user experience will be unpredictable. Many years ago, there were no strict standards and the experience of each web page on different user agents was different. So W3C made more strict standards so that however the page displays on one web browser, it should display the same on a different browser.

Now if you test the correctness of your website by pasting your code on their validator, you will see that it will not pass the tests.

And for your information, < header > section and < head > are different (just in case you want mix them up). You can put divs in < header > as of HTML5, but never in < head >.

Further reading:

  1. http://www.w3.org/TR/html401/struct/global.html
  2. http://www.w3schools.com/tags/tag_header.asp
  3. http://validator.w3.org/#validate_by_input
Wagonette answered 28/9, 2014 at 19:22 Comment(0)
F
4

<head> should never contain <div> and such is is reserved for metadata like js-scripts, name of the page, loading css ...

If you want to duplicate a part of a website in several pages you could use php.

You could for example put at the begining of your <body> :

<?php include ('header.php'); ?>

And put the html of your header in a header.php.

(Note that you will need to run a server like wamp to test your website localy if you use php)

Flaccid answered 28/9, 2014 at 19:13 Comment(1)
this really should have a source. It's just an assertion that div doesn't work in head. evidence?Crofter
E
0

A div is not semantic, but that does not mean it is bad to use it...

But now, you want to use it in the head tag. Well, that is very very bad. The head tag is meant for metadata, not for building elements.

Esterify answered 28/9, 2014 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.