tags:

views:

33

answers:

2

I have menu.php, and in the <head> section of menu.php, I have menu.css as a link rel tag of course, both of which work perfectly fine.

Since menu.php is a 'menu', I've required it on pages that need a 'menu' in order to navigate around the website. However, whenever I require menu.php on a page that has its own CSS stylesheet, menu.php inherits the <body> font-size of the other stylesheet.

Here is what I'm trying to say: So if I require menu.php on profile.php, menu.php elements will become the size of profile.css, instead of what they really ought to be(menu.css). How can I fix the following problem? Currently, I am requiring menu.php BEFORE the <html> tag.

Should I put this within <head>? Somewhere else?

Thank you.


Some of the code from menu.php:

<html>
<head>
<link rel="stylesheet" type="text/css" href="menu.css" />
</head>
<body>
</body>
</html>

I've put my PHP code before the <html> tag in the file above.

The below code comes from main.php:

<head>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
A: 

Could you paste the content of your menu.php? Because if there are and section there...you're doing it wrong, because in that way you're going to have two head and two body parts. Think for require in php as copy and paste.

Your options:

  • Migrate to some template system(as Smarty for example).
  • If there should be menu.php on each page, why not putting this css as static file in the header
  • Paste some code, so we could help you easier ;)
Vladimiroff
@ Vladimiroff - I've added the code from my files in the edited section. Thank you.
Newbie_25
+1  A: 

If I understand you correctly, you include a complete html page generated by menu.php before the html in main.php. That would get you 2 <html> sections, 2 <body> sections, etc. in one document. That should lead to lots of trouble.

You should include your menu in for example a div inside the main page like (just an example):

main.php:

<body>
<div id="nav">
<?php require 'menu.php'; ?>
</div>
...
</body>

and put all menu styles in the main style-sheet, pre-fixed with #nav. Or as a separate style-sheet, but still pre-fixed with #nav (every style) so that they overwrite the main document's styles.

jeroen
@Jeroen - Thank you for your help. :)
Newbie_25
You're welcome!
jeroen