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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.