What is the advantage of including the Opening <DIV> command in the header file, rather than leaving it in the HTML file
In the last video I watched, the tutor created an INCLUDE file called header.php. This was created by copying all the header information from the basic HTML page, but she ALSO copied the opening <DIV> command of the 'main' HTML section of the page. Why?
Also, the same header.php file was used in a new file which (as far as I could see) did not have a corresponding closing </DIV> command, but no error was shown. Why??
Jason AndersTreehouse Moderator 144,865 Points
She included the opening <div> because the tag will be common in all the pages the header is used (included) in. The closing tag for that
div is actually in
footer code, which is included in all the pages the header file is included in.
So, it opens in the
header file and closes in the
footer file. If you didn't
footer file, you would encounter an error, yes.
Hope that makes sense. Keep coding! :)
Ah! That makes sense now. Thanks very much! I do use html includes myself but have always left the 'content' of the page intact so that it would remain useful on a standalone basis even if something went wrong with the includes or links to them. Irrational fear, I guess!
Muhammad Athar4,004 Points
First time learning about includes. Does feel kinda awkward putting an opening tag in a separate file. Had to stop the video and come here to look why. I guess it'll take time to make it a habit.