Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

96 LESSON 6: Working with Links


When you specify just the filename of a linked file within quotation marks, as you did
earlier, the browser looks for that file in the same directory as the current file. This is true
even if both the current file and the file being linked to are on a server somewhere else
on the Internet; both files are contained in the same directory on that server. It is the sim-
plest form of a relative pathname.
Relative pathnames point to files based on their locations relative to the current file. They
can include directory names, or they can point to the path you would take to navigate to
that file if you started at the current directory or folder. A pathname might, for example,
include directions to go up two directory levels and then go down two other directories to
get to the file.
To specify relative pathnames in links, you must use UNIX -style paths regardless of the
system you actually have. You therefore separate directory or folder names with forward
slashes (/), and you use two dots to refer generically to the directory above the current
one (..).
Table 6.1 shows some examples of relative pathnames and where they lead.

TABLE 6.1 Relative Pathnames
Pathname Means
href=”file.html” file.html is located in the current directory.
href=”files/file.html” file.html is located in the directory called files (and
the files directory is located in the current directory).
href=”files/morefiles/file.html” file.html is located in the morefiles directory, which
is located in the files directory, which is located in the
current directory.
href=”../file.html” file.html is located in the directory one level up from
the current directory (the parent directory).
href=”../../files/file.html” file.html is located two directory levels up, in the direc-
tory files.

Absolute Pathnames


You can also specify the link to another page on your local system by using an absolute
pathname.
Absolute pathnames point to files based on their absolute locations on the file system.
Whereas relative pathnames point to the page to which you want to link by describing its
location relative to the current page, absolute pathnames point to the page by starting at
Free download pdf