
Originally Posted by
wanapitei
Quite correct, it's working on one page and not on the other. It's been my assumption (and it's just that, an assumption) that the ../ directs the reference to begin from the root.
../x refers to some "x" located in the folder above the current folder of the script being executed.
so in your case ../stylesheet inside the "Doc that doesn't work"
if written in absolute terms refers to
Code:
root > folder > stylesheet
If that were true then if that syntax works for one page, then it should work for another, one step further down. I'm assuming here that when the page looks for the CSS code it starts at the root and proceeds to look down to the address given.
Is this
not a reliable syntax? Or have I misunderstood the ../ convention?
I believe you mis-understood the convention. Whenever you use a relative path it starts from the folder the file being executed is in. So
Code:
Root > Folder > Doc that works
with the stylesheet declaration of
Code:
<link type="text/css" rel="stylesheet" href="../styles.css">
refers to
I should note here that I'm working both on my Mac and on my server (not a Mac) where the root is morleychalmers.com. I've set up within that a directory for the forthcoming website, a folder called MostlyTheravada. When the final server and domain is put together, it's the MostlyTheravada directory which will be the root of the website.
If this is a web site page that you are referring to, it doesn't matter because all web site page paths are declared the same way.
I'd like to preserve the flexibility of relative paths and avoid hard coding absolute paths. Is this not an appropriate setting to develop a new site and domain?
Appreciated.
Its not mandatory that you develop a new site.
You are correct, using relative paths for a document on the same domain are, in my subjective opinion, the best way to reference. However when a file is moved from folder A to folder B, it requires the developer to redo all of the relative paths due to the move. This is why I like using something called an absolute relative path. what I mean by that is use the domain as the "root" and go from there..
so from any folder on the website, if you start the relative path with a forward slash (/) it will actually start the link from the domain.
so for the website
Code:
www.dynamicdrive.com
with files
Code:
www.dynamicdrive.com/forums/thread.php
www.dynamicdrive.com/scripts/script.php
www.dynamicdrive.com/styles/css/style.php
with the same exact css external link declared as
Code:
<link type="text/css" rel="stylesheet" href="/css/stylesheet.css">
would all refer to the file
Code:
www.dynamicdrive.com/css/stylesheet.css
I hope I didnt confuse you, but the moral is that if you are working on a web site page, and you wish to reference something using a relative path of the domain, use the forward slash, and it will start the anchor at the document root, which you than can drill down into the correct folder and file that you need
Bookmarks