Tell me more ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

Is this possible? I can't find an example of this on the internet anywhere. I am struggling with what should be really simple CSS code. Can anyone tell me what is wrong with this code? The .css wont load into the page even though I think I have configured it correctly. All 3 files are in the root of the web directory.

<head><title>main.php</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<?php include("header.php");?>
</body>
</html>

And my .css file is:

div#header{
 position:absolute;
 top:0;
 left:0;
 width:100%;
 height:header-<length>;
 background-color:yellow;
}

My header.php is:

<?php echo "<div>";      
print "header.php";     
echo "</div>"; ?> 
share|improve this question

closed as off topic by Alex, phwd Mar 31 '12 at 7:31

Questions on Web Applications Stack Exchange are expected to relate to web applications within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote 1 down vote accepted

Without knowing the contents of "header.php", I can't say for certain, but here's a few things to check:

  • add type="text/css" to your link tag. Probably not required, but it never hurts to have it.
  • ensure that "styles.css" is in the same path as your HTML file. If it isn't, make sure to use relative or absolute paths to point to the appropriate place.
  • ensure that you have a DIV with the id of "header" in your header.php file so that the styles in your .css file have something on which to act.
  • finally, the rule for "height" in your .css file is invalid. You can't do arithmetic in valid CSS, so go with a straight pixel, percentage, or em-based height (e.g., 100px).
share|improve this answer
I tried all your suggestions. Updated my question a little bit. If you try my code, you will see the problem I think. – djangofan May 27 '11 at 4:17
Your DIV needs to have an ID of "header". It should look like <div id="header">. Whatever is in side is immaterial, granted, but you need the ID in place so that your CSS can target it. Finally, your CSS rule on "height" will need to change as well, otherwise you won't see anything happen because the height will probably be set to 0. Give it a fixed height (like 100px) for now, and see how it works out. – Kerri Shotts May 27 '11 at 4:26
Finally figured it out. I was missing the "id" in the DIV. Thanks for your help! – djangofan May 27 '11 at 4:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.