Creating Anchors


Generally, a click on a link brings the user to the top of the corresponding Web page. If you want to have the user jump to a specific section of the Web page, you have to create an anchor and then reference that anchor in the link.

To create an anchor:

1.

Place the cursor in the part of the Web page that you wish the user to jump to.

2.

Type <a name="anchor name">, where anchor name is the text you will use internally to identify that section of the Web page.

3.

Add the words or images that you wish to be referenced.

4.

Type </a> to complete the definition of the anchor.

Figure 6.8. Notice that most of the anchors are created with the a element and name attribute, while the last is created by simply adding an id attribute to the existing h2 element (see first tip). The id attribute does double duty as an anchor in all but the oldest browsers.


Tips

  • You can also create an anchor by adding an id attribute to the desired element (see page 63).

  • Quotes are always required around the anchor name in XHTML. While they're sometimes optional in HTML (see page 38), I highly recommend them.

  • In a long document, create an anchor for each section and link it to the corresponding item in the table of contents.

  • The W3C, Netscape, and others are not at all consistent with the terminology. Some folks call links anchorsa is for anchor, after allothers call targets anchors. In this book, the word anchor refers to a specific location in a document that you link to. (A target is the window or frame where a link will appear. See page 108.)





HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

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