This page includes:
Understanding PathsWe won't beat around the bush. Understanding how paths work is, without a doubt, the most difficult thing to learn for a beginning web page creator. Broken links, or bad paths, are the reason why we didn't want you to use an HTML editor as you began to go through our beginning tutorials. HTML editors can create bad paths for you that you wouldn't know how to correct. The good part about getting through this tutorial is that you will be completely ready to use an HTML editor after this point, because you will know how to correct any mistakes it may make. Hooray!
Examples of bad paths:
Absolute and Relative URLsThere are two types of paths in HTML, known as relative paths and absolute paths. An absolute path contains the full URL of the item being referenced. A relative path contains directions to the item relative to the HTML page.
Example: you're creating a page that will be uploaded to:
![]() ![]() Important: Domain names are not case sensitive, but directories and filenames are! You'll have an easier time understanding this if you've dealt with DOS or UNIX where files are not kept in icon-assigned folders, but instead you have to navigate the tree structure of your directories. If you've only used a Mac or Windows 95, you may need to fight your way through understanding URLs and paths a little harder. Let's say there's an image, also in the directory (folder) that is named "example", and the image is named voyage.gif. Using the IMG SRC tag, which adds a graphic to a page, the absolute path for the image would be: <IMG SRC="http://www.webdiner.com/example/voyage.gif"> The relative path for that image, from the index.htm page, would be: <IMG SRC="voyage.gif"> This would point to a graphic named voyage.gif, uploaded to the same directory on the web server as the HTML page that referenced it. Relative URLs are preferred for your own pages. If you change domains, and you've used relative URLs for your graphics and web pages, you won't need to edit the links if you do change domains. If your web site grows and grows (as ours did!) you might need to change hundreds of links if you ever move your web site.
More Relative URL TipsLet's say that the page you are writing will be uploaded as:http://www.webdiner.com/example/index.htm and a graphic, in another folder, at the URL http://www.webdiner.com/images/fiddle.gif The path from the HTML page to the graphic:
Absolute Path: The relative path tells the browser to look in a directory named images for a file named fiddle.gif. If the image was located at the URL: http://www.webdiner.com/images/music/fiddle.gif
The relative path would appear as: Let's say that the page you are writing will be uploaded as: http://www.webdiner.com/example/index.htm and the graphic you want to link to is located at: http://www.webdiner.com/tuba.gif The path from the HTML page to the graphic would look like this:
Absolute Path: The ../ in the HTML tag tells the browser to go up one directory level. If the graphic was up two directory levels, the relative path would look like this: <IMG SRC="../../tuba.gif"> At this point, we've created relative paths to images that are in the same directory, in a directory on the same level, and in a directory that is up one level, and a directory that is up two levels. Phew! Most HTML editors will create links for you. However, some HTML editors will create an absolute link to a graphic...on your hard drive! This will, of course, be useless once you upload your web page. A bad link to a graphic created by an HTML editor will look like this: <IMG SRC="c:\\pagemill\images\filename.gif"> Yowza! If you see anything like that in a problem web page, edit the HTML to create a correct link. The giveaway that this link won't work is that it contains slashes going the wrong direction, and a reference to c:, or the c drive on a computer. Also remember that you will need to mirror your directory structure on your computer and on your web site. This way, links will work both when you test the page on your computer and also once you upload both the HTML file and the graphic. HTML for Paths - A HREF and IMG SRCTo create a link in a web page, you use the <A HREF="filename.htm"> tag, which is followed by a closing </A> tag. Any text between the Anchor H Reference, or A HREF tag, and its closing tag, will become a clickable link. The default color for this clickable link text is blue. If you would like a different color, you will need to specify it with a hexcode.You can link to anything on the web, using either a relative or absolute URL.
<A HREF="http://www.yahoo.com"> Search the Web! </A> Using an Image as a LinkTo add an image as a link, you'll use the IMG SRC tag to point to the image:<IMG SRC="icon.gif"> And then create your link: <A HREF="http://www.yahoo.com"> <IMG SRC="icon.gif"> </A> This will create a clickable image. The icon will have a border (the default is a blue line, determined by the LINK attribute of the BODY tag). You can remove the "blue line" around your image by including the BORDER=0 attribute: <A HREF="http://www.yahoo.com"> <IMG SRC="icon.gif" BORDER=0> </A>
Q. My image doesn't show up on my web page!
|