Index.php
<html> <body>
<head> <link rel="stylesheet" type="text/css" href="mydesign.css"> </head>
<?php require("layout.php"); ?>
<div id="content">
my text and titles go here
</div>
</html> </body>
First of all, you need to put the body tag opening
after the head tag. Which is what you have done in the second code box. Just a side note here, it causes mobile browser incompatibility. Also, you're closing <html> before you do the body tag! You gotta be careful with these in the future.
Now, talking about the code you've got there, it's good. Although I wouldn't call it layout.php and more like header.php, just to be clear. You might also want to make a footer.php and use include() or require() to get a footer after your content div as well.
BUT, the way you've done your layout.php isn't correct. Because now this is the page source after being processed by apache and sent to the browser(notice i've fixed the tag orders for you):
<html>
<head> <link rel="stylesheet" type="text/css" href="mydesign.css"> </head>
<body>
<html>
<head> <link rel="stylesheet" type="text/css" href="mydesign.css"> </head>
<body>
<div id="header">
logo </div>
<div id="menu">
home - pictures - more - more
</div>
</body></html>
<div id="content">
my text and titles go here
</div>
</body></html>
Now, notice you now have 2 heads, 2 bodies, 2 stylesheet links and 2 htmls. This puts the browser in quirks mode. You only have to get the stylesheet once, as the contents of both of these are represented in the same page. So, change your layout.php to this:
<div id="header">
logo </div>
<div id="menu">
home - pictures - more - more
</div>
And now the code output on the page will be this:
<html>
<head> <link rel="stylesheet" type="text/css" href="mydesign.css"> </head>
<body>
<div id="header">
logo </div>
<div id="menu">
home - pictures - more - more
</div>
<div id="content">
my text and titles go here
</div>
</body>
</html>
Also, notice you're lacking a title tag in your head tag, remember to include that, too!
And yes, as web_designer said, you can use the require() or include() functions in php code to get the stylesheets and scripts embedded in the head tag. Doing this will reduce the amount of http requests required for the browser to make and further optimizes your website if you're using a heavy CSS file. If you want to do the thing mentioned above, get rid of the stylesheet link in the head tag and use this instead:
<head><style type="text/css"><?php require("mydesign.css"); ?></style></head>
Good luck.
Edited by Baniboy, 27 February 2010 - 01:57 PM.