Here's my directory structure:
-ro开发者_Go百科ot
--docs
---doc1.php
--includes
---header.php
---footer.php
---css.css
--index.php
In my header, I link to my CSS file like so:
<link href="includes/styling.css" type="text/css" rel="stylesheet" />
That works for index.php, because it's the correct path (root/includes/css.css).
But for doc1.php, it's not the right path. (root/docs/includes/css.css).
How do I fix this while keeping one header.php file with that line of code in it? Is there a way to force the path to start in the root directory?
Use an absolute instead of a relative path.
<link rel="stylesheet" type="text/css" href="/root/includes/css.css" />
You can use the base tag to tell the browser where all links are relative to (including s and s), you will need to make sure all your links are relative to that, but it will allow you to use the same relative path from any document.
Or, you could use an absolute path.
Or this will remove all doubt for any page, at any level:
<link rel="stylesheet" type="text/css" href="http://www.mysite.com/includes/css.css" />
精彩评论