Reputation: 953
I have some problem specifying css and image paths in my website. It works well when i'm in the same folder level but quickly breaks up when i'm in another folder. I'm working in localhost and my directory structure is like this:
ROOT
main.php
/subfolder/file2.php
/templates/template1.php
/style/style.css
I have already called style.css in template1.php.
I can call main.php from template1.php (using include) and CSS works fine. The problem is when I call file2.php from template1.php, the CSS is no longer called.
How can I specify the paths so that CSS or images is properly linked no matter at which folder I am in?
Upvotes: 0
Views: 37
Reputation: 1212
Using an absolute path to the css file might be the simplest, if it's possible. Otherwise, with more complex structures, Rasclatt's method is the way to go. I often just assign a path variable at the top of the php page.
Upvotes: 1