#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    USA
    Posts
    140
    Rep Power
    12

    OO CSS? Creating single CSS file and including with php on many pages


    I have a single CSS file that I'm using all over the place on my website. When I edit the file, I have to copy it to each directory to make sure that each directory is using the same file.

    I would like to have a php file in each directory that I can include with the same code in every file, that points to the CSS file in the root directory of the site.

    I tried putting this in the html of the page:

    Code:
    <?php include('styleref.php'); ?>
    Then put this in styleref.php:

    PHP Code:

    <link rel="stylesheet" type="text/css" href="http://www.website.com/layout.css"
    But this didn't work.

    Any hints?
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    No need to have PHP do anything. Put your layout.css file in the document root and use the following:
    Code:
    <link rel="stylesheet" type="text/css" href="/layout.css" />
    B/c you precede layout.css with a forward slash in the href attribute, it will look for that file relative to the document root instead of relative to the current directory, which is where it looks if you don't preced the filename with a forward slash.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    USA
    Posts
    140
    Rep Power
    12
    What would be considered the root of a website? The directory containing the files displayed when you go to "website.com"?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    USA
    Posts
    140
    Rep Power
    12
    Figured out the root. Appears it is the "htdocs" folder when running Apache.

    Thanks Jeremy.
  8. #5
  9. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    What would be considered the root of a website? The directory containing the files displayed when you go to "website.com"?
    Yes, but ...
    Appears it is the "htdocs" folder when running Apache.
    ... isn't always the case.

    But for now, do what's working.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.

IMN logo majestic logo threadwatch logo seochat tools logo