Question

I was working in HTML, when I started having trouble referencing different pages, I started using data/css/styles.css and that worked fine on the page in the main directory of the Website (not inside any other folders), then when I did the same thing in a sub-directory (eg. "/home/") it didn't work. So I then tried using the standard /data/css/styles.css, that also didn't work in either the main or sub directories. So then I tried my final attempt with ../data/css/styles.css with luck on sub-directories but not the main. But when I the second (/data/css...) and the third (../data/css) on JSFiddle they worked fine. Is there something wrong with my compiler (Visual Studio Web Developer 2010) or is the debugging strange? Thanks in advance.

Was it helpful?

Solution

If the pathname begins with /, it is interpreted relative to the DocumentRoot of the website. If the pathname does not begin with /, it is interpreted relative to the URL of the page containing the link. So if a page with path /a/b/c.html contains the link dir1/dir2/foo.css, it is converted to /a/b/dir1/dir2/foo.css. ../ prefixes are used to back up by a directory in the pathname, so if the page contains ../dir1/foo.css, it's converted to /a/dir1/foo.css.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top