HTML and CSS Reference
In-Depth Information
NOTE
Top has different meanings, depending on how you publish your
HTML files. If you just link to files on your local disk, the top is the
top of your file system (
/
on UNIX, or the disk name on a
Macintosh or PC). When you publish files using a web server, the
top is the directory where the files served by the web server are
stored, commonly referred to as the document root. You learn
more about absolute pathnames and web servers in Lesson 20,
“Putting Your Site Online.”
Table 6.2 shows some examples of absolute pathnames and what they mean.
TABLE 6.2
Absolute Pathnames Examples
Pathname Means
href=”/u1/lemay/file.html” file.html
is located in the
directory
/u1/lemay
(typically on
UNIX systems).
href=”/d|/files/html/file.htm” file.htm
is located on the
D:
disk in the directory
files/html
(on Windows systems).
href=”/Macintosh%20HD/HTML Files/file.html” file.html
is located on the disk
Hard Disk 1
, in the folder
HTML
Files
(typically on OS X systems).
Using Relative or Absolute Pathnames?
The answer to that question is, “It depends.” If you have a set of files that link only to
other files within that set, using relative pathnames makes sense. On the other hand, if
the links in your files point to files that aren't within the same hierarchy, you probably
want to use absolute links. Generally, a mix of the two types of links makes the most
sense for complex sites.
6
Let's say that your site consists of two sections,
/stuff
and
/things
. If you want to link
from the file
index.html
in
/stuff
to
history.html
in
/stuff
(or any other file in
/stuff
), you use a relative link. That way, you can move the
/stuff
directory around
without breaking any of the internal links. On the other hand, if you want to create a link
in
/stuff/index.html
to
/things/index.html
, an absolute link is probably called for.
That way, if you move
/stuff
to
/more/stuff
, your link will still work.
The rule of thumb I generally use is that if pages are part of the same collection, I use
relative links, and if they're part of different collections, I use absolute links.