Jump to content

[SOLVED] Header CSS Location Help


chordsoflife

Recommended Posts

So here's my situation:

 

I've created header/footer files, and included them in all the pages of my website. My problem is that in the header file, I have

 

 

link href="css/default.css" rel="stylesheet" type="text/css"

 

which doesn't apply for each page, since I have some pages in folders for organizational issues. Is there a way to make that reference dynamic somehow? I don't even know if my thinking is correct. I've seen $_SERVER['DOCUMENT_ROOT'] been used, but tried it and received errors. I'm not sure if I set it up correctly.

 

Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/
Share on other sites

I believe you're saying you're putting the link to the CSS file in each page of your site. And some of these pages reside in a different folder, so the path to the CSS is wrong.

 

If so, your URL just needs to be spruced up a little. From the root of your domain, trace the path. If CSS is a directory under the root directory, your code would be:

<link href="/css/default.css" rel="stylesheet" type="text/css">

 

Notice the slash beginning the URL. That will make all the difference.

I tried that and it didn't work. My files aren't under the root, they're above it, so on most, the css file would be located at "css/default.css" but for others it would be "../../css/default.css". My issues is that I'd like to use the same header file (which contains the link line) for all of my files.

 

I definitely appreciate the help. The ball is rolling.

Just an idea, and maybe it's going to be a bit backwards, but if you created a database and put the path to your stylesheets in that database, then do a query something like (and this is not proper syntax)

 

SELECT * FROM stylesheets WHERE page_id = 'trees'

 

Then put the data returned into a variable, you could have your link as such

<link href="<? php echo $trees; ?> />

 

Just an idea

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.