No CSS from include.php from level up directory

174 Views Asked by At

I've searched around and found people with similar problems, but nothing suggested seems to work for me.

Here's my file structure...

CSS
  > style.css
INCLUDES
  > header.php
  > footer.php
IMGS
index.php
contact.php
about.php
terms.php
MUSEUM-PAGES
  > dummy.php

the header.php which contains the link to css works fine for any html/php page that isn't nested in a sub-directory.

But when I use a sub-directory to better organise the files it falls apart. In this example museum-pages > dummy.php can't bring in the css. The content from the header and footer work fine, just not the CSS files.

I tried replacing the

<link rel="stylesheet" href='css/style.css' type="text/css" media="screen" title="no title" charset="utf-8"> in the header.php to...

/css/style.css
.
../
../../

but it will drop all non-sub directed references in other pages, such as the homepage. I am baffled. Anyone able to help me please?

2

There are 2 best solutions below

7
On

This should work fine?

<link rel="stylesheet" href='/css/style.css' type="text/css" media="screen" title="no title" charset="utf-8">

The / is 'root'

EDIT

Since this didnt work, you could try this below, it isnt good practice IMHO however.. it will work.

<?php

// this is your header.php file

$linkToCss = "http://yoursite.com/css/styles.css";

?>

<link rel="stylesheet" href='<?php $linkToCss; ?>' type="text/css" media="screen" title="no title" charset="utf-8">

If that doesn't work there is another issue going on - try it see if it works.

2
On

Use an absolute path:

<link rel="stylesheet" href='/css/style.css' type="text/css" media="screen" title="no title" charset="utf-8">