Section 11.1. Simple Hypertext Links


11.1. Simple Hypertext Links

The anchor (a) element is used to identify a string of text or an image that serves as a hypertext link to another document.

a

 <a>...</a> 

Attributes

Core(id, class, style, title)
Internationalization
Events(plus onfocus, onblur)
accesskey="character"
charset="charset"
coords="x,y coordinates"
HRef="URL"
hreflang="language code"
name="text"
rel="relationships"
rev="relationships"
shape="rect|circle|poly|default"
tabindex="number"
target="text"
type="media type"

The HRef attribute provides the pathname (URL) of the document to which you want to link. URLs can be absolute or relative, as discussed in the next sections.

A text link is marked up like this:

 I am <a href="link.html">linking</a> to you! 

To make an image a link, enclose the image element in an anchor as follows:

 <a href="link.html"><img src="/books/4/439/1/html/2/pixies.gif"></a> 

By default, most graphical browsers display linked text underlined and in blue, but this presentation can be altered with style sheets. Linked images appear with a blue border by default unless you change this setting with the border style property or the deprecated border attribute in the img element.

11.1.1. Absolute URLs

An absolute URL is made up of the following components: a protocol identifier, a hostname (the name of the server machine), and the path to the specific filename. When you are linking to documents on other servers, you need to use an absolute URL. The following is an example of a link with an absolute URL:

 <a href="http://www.littlechair.com/web/index.html">...</a> 

Here, the protocol is identified as http (HyperText Transfer Protocol, the standard protocol of the Web), the host is www.littlechair.com, and the pathname is web/index.html.

11.1.2. Relative URLs

A relative URL provides a pointer to another document relative to the location of the current document. The syntax is based on pathname structures in the Unix operating system, which are discussed in Chapter 4. When pointing to another document within your own site (on the same server), it is common to use relative URLs.

For example, if I am currently in resume.html (identified here by its full pathname):

 www.littlechair.com/web/work/resume.html 

and I want to put a link on that page to a document named bio.html that is in the same directory:

 www.littlechair.com/web/work/bio.html 

I could use a relative URL as the href attribute value as follows:

 <a href="bio.html">...</a> 

Using the same example, to link to the file index.html in a higher-level directory (web), I could use the relative pathname to that file as shown:

 <a href="../index.html"> 

This relative URL is the equivalent to the absolute URL http://www.littlechair.com/web/index.html.

11.1.3. Establishing a base

By default, a relative URL is based on the current document. You can change that by placing the base element in the document header (head) to state explicitly the base URL for all relative pathnames in the document.

base

 <base /> 

Attributes

(XHTML only)
href="url"(Required)
target="name"

The base element may appear only in the head of the document, and it should appear before any other element with an external reference. The browser uses the specified base URL (not the current document's URL) to resolve relative URLs. The base element is also useful in specifying a target frame for relative links in a framed document (see Chapter 14).




Web Design in a Nutshell
Web Design in a Nutshell: A Desktop Quick Reference (In a Nutshell (OReilly))
ISBN: 0596009879
EAN: 2147483647
Year: 2006
Pages: 325

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net