Linking PHP files to nested files
I've built a site where I have a header.php file, index.php and footer.php. In the header.php file I am calling the .css files that I am using, which live in the root directory. I then have my work pages, which live in their own folders and each have an index file (mountain_bike/ is a folder that lives on the root with an index.php file for the mountain bike page). For some reason when I do this, I can access the same header and footer files despite being in the folder, but the css file is not being read. Is there another step I should take or another way of going about this? Thanks.
Just use the exact root location instead of the relative root.
What do you mean by that?
In my header.php file I have this...
The header file and css files live on the root. The mountain_bike/index.php is still using the same header file as the home page. So I did this..
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="portfolio_style.css">
The header and footer both are linked to the mountain_bike/index.php, but the CSS is not being applied.
Sorry if I'm duplicating efforts, wasn't sure what you meant.
Well It could be two things then.
Originally Posted by andy.richin
1. the href isn't correct.
2. the php isn't referencing it correctly.
In either case, you can use the EXACT location.
i.e your website/location of file moving from the root.
First make sure the href is referencing it correctly.
If you narrow it down to the php, try using exact location.
Or even try using inline to make sure the css is correct.
So I guess it could be three things.
Ok thanks. One other thing, could it be the fact that I'm building this site in a DEV folder? So I guess it's not actually on the root, but it's all inside the DEV.
yes that would have something to do with it. when you do /x it looks in the current folder location for the file you are referencing.
So I moved everything to the root and still nothing. Everything works fine if I have example.php, header.php and style.css living in the same directory. Example.php is calling header.php which calls style.css. As soon as I move example.php into a folder example/index.php the style sheet stops working. The header still works, I'm calling
I don't know if I'm missing something. It seems pretty straight forward but not working. The href is right and php looks right too.
Is this really that difficult? :/
Just a use a leading slash in the href property to indicate the CSS file's location relative to the web root:
<link rel="stylesheet" type="text/css" href="/style.css" />
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)