当前位置: 代码迷 >> 综合 >> 什么是锚(anchor)
  详细解决方案

什么是锚(anchor)

热度:37   发布时间:2024-01-05 04:40:08.0

anchor的定义:

Definition:

An anchor is another word for internal link or bookmark on a web page. An anchor is a link that links within the same page of the document.

Alternate Definition of Anchor

Some designers use the term anchor to refer to any hyperlink on a web page. This definition stems from the fact that the HTML tag to create a link is the <a> tag or anchor tag.


internal links定义:

Definition:

An internal link is a link on a web page that links to another page on the same site or domain. Most internal links are used as navigation around the site or to provide additional information about a topic.

Alternate Definition of an Internal Link

Beyond being links to other pages on the same domain, internal links (often calledbookmarks or ) are also the links within one page. These links are usually found in tables of contents or as navigation within a long page. They allow designers to point to just the part of the page that is relevant.


<a>标签,anchor、link

A key feature of the web is the ability to connect (hyperlink or ‘link’) resources, including webpages, media files (images, video, etc.) and programs.

A hyperlink can be made from a document to:

  • a different resource      (source anchor)
    For example from a webpage to a Word document, or
  • a location within the current document   (destination anchor)
    For example from a menu at the top of the page to a point somewhere else on the same webpage.

Both the source and the destination of a link are referred to as anchors.


Source anchors

A source anchor is created in an HTML document (webpage) by adding an anchor element (<a>) with a hypertext reference (href) containing a uniform resource identifier (URI).

Using the code for a link to the Motive homepage as an example:

This glossary is compiled by <a href="http://www.motive.co.nz">Motive</a>.

<a href="http://www.motive.co.nz">Motive</a>.

         \_________URI_________/ 

   \_______href attribute_______/ 

\______________(source) anchor_____________/


Destination anchors

A destination anchor is often referred to by users as a ‘jump-to link’. In FrontPage it is called a ‘Bookmark’ and in Dreamweaver, it is a ‘Named anchor’.

To link to a point within a webpage, for example to link to content below the first fold, a destination anchor must be added.

A destination anchor is created by adding a fragment identifier, this is either:

  • an anchor element, with a name attribute, or
  • any other element, with an id attribute.
Hyperlink Element Destination anchor code Source anchor code
Page top <a> <a name="pagetop"></a> <a href="#pagetop"> Page top </a>
Content <a> <a name="content"></a> <a href="#content"> Content </a>
Destination anchors <h2> <h2 id="destination"> Destination anchors </h2> <a href="#destination"> Destination anchors </a>

ASSUMED #TOP ANCHOR

If creating an destination anchor to scroll to the top of the current page, be advised that some browsers [1] appear to ‘assume’ a #top anchor (not visible in the page source code). As implementation of this feature appears inconsistent, it is preferable to insert a #pagetopdestination anchor instead: <a name="pagetop" id="pagetop"></a>.