You create an anchor in nearly the same way that you create a link: by using the <a> tag. If you wondered why the link tag uses an
<a> rather than an <1>, now you know: a actually stands for anchor.
When you specify links by using <a>, the link has two parts: the href attribute in the opening <a> tag and the text between the opening and closing tags that serve as a hot spot for the link.
You create anchors in much the same way, but rather than using the href attribute in the <a> tag, you use the name attribute. The name attribute takes a keyword (or words) that name the anchor. Figure 5.11 shows the parts of the <a> tag. When used to indicate an anchor.
FIGURE 5.11 the <a> tag and anchors.
Including text between the anchor tags is optional. The actual anchor is placed at the location of the opening anchor tag, so you can just as easily write it as
<a name=”my anchor”></a>
The browser scrolls the page to the location of the anchor so that it’s at the top of the screen.
For example, to create an anchor at the section of a page labeled part4, you might add an anchor called part 4 to the heading, similar to the following:
<h1><a name=”part4”>part four” Grapefruit from heave</a></h1>
Unlike links, anchors don’t show up in the final displayed page. they are just a marker that links can point to.
To point to an anchor in a link, use the same form of link that you would when linking to the whole page, with the filename or URL of the page in the href attribute. After the name of the page, however, include a hash sign (#) and the name of the anchor exactly as it appears in the name attribute of that anchor (including the same uppercase and lowercase characters!), like the following.
<A HREF=”MYBIGDOC.html#poart4”>Go to part 4</a>
This link tells the browser to load the page my big doc. Html and then to scroll down to the anchor named part4. The text inside the anchor definition will appear at the top of the screen.
No comments:
Post a Comment