Search code examples
cssstylesheet

Reffering to a css stylesheet from an unknown, higher directory


I'm currently in the process of building my first PHP-based website. The entire website is located in the main directory: example.com

I want users to find different pages of my website by going to links like example.com/page, example.com/another_page, example.com/directory/some_page, etc. etc.

To do this, I make these directories, and add the following php-code in an index.php:

<?php
include("/home/user/domains/example.com/public_html/index.php");
?>

This works fine, the page is being included. The problem is that the stylesheet isn't. It only works in the main folder. I tried both these HTML-snippets:

<link href="Stylesheet.css" rel="stylesheet" type="text/css" />
<link href="/home/user/domains/example.com/public_html/Stylesheet.css" rel="stylesheet" type="text/css" />

But they both don't work.

How does this work in HTML, how to access the home directory?

Thanks in advance


Solution

  • The css file is downloaded and included on the client side, as opposed to the php include statement which includes the file on the server side.

    The path for the css should therefor "make sense" from the clients perspective and probably be specified relative to the public_html directory. That is, if it resides directly in the public_html directory the line should read

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