Home  >  Article  >  Web Front-end  >  How to use anchors in html web pages

How to use anchors in html web pages

php中世界最好的语言
php中世界最好的语言Original
2018-02-10 09:11:482284browse

This time I will show you how to use the anchor point in the html web page, what are the precautions for using the anchor point in the html web page, the following is a practical case, let's go together take a look.

Anchor point is a type of hyperlink in web page production, also called named anchor. A named anchor is a hyperlink within a page, like a quick locator, and is quite commonly used.
English name: anchor
Use named anchors to set tags in the document. These tags are usually placed at or at the top of a specific topic in the document. Links to these named anchors can then be created that quickly take visitors to the designated location.
The process of creating a link to a named anchor is a two-step process. First, create a named anchor, and then create a link to the named anchor.
Sample code
Define the following anchor point at the appropriate location in the HTML page:

<a name="top">这里是TOP部分</a> 
<a name="content">这里是CONTENT部分</a> 
<a name="foot">这里是FOOT部分</a>

(You can use the id attribute to replace the name attribute, and the naming anchor is the same Valid. [1])
There are two ways to access the above anchor points
One is to use the hyperlinktag3499910bf9dac5ae3c52d5ede73834855db79b134e9f6b82c0b36e0489ee08ed to create an anchor link. Used for anchor point access within the page

<a href="#top">点击我链接到TOP</a> 
<a href="#content">点击我链接到CONTENT</a> 
<a href="#foot">点击我链接到FOOT</a>

Another way is to add the anchor point mark directly after the page address, mainly used for anchor point access between different pages
If this page The address is http://file path/index.html. To access the foot anchor point, just access the following link
http://file path/index.html#foot
2.html What is the anchor point? What for?
To put it simply, for example, if you want to read a long article accurately by segment, you can use anchor points.
Code:

<a href="#001">跳到001</a> 
...文字省略 
<a name="001" id="001" ></a> 
...文字省略

In fact, the anchor point only needs name. The id is added to make it more compatible.
The value of href must be consistent with name \ i d, as shown above "#" must be added. The above code is compatible in ie6/7 and ff, but not in ie8.
Because the 3499910bf9dac5ae3c52d5ede73834855db79b134e9f6b82c0b36e0489ee08ed value of our anchor point is empty, we can just add a space so as not to affect the appearance.
The following code will be compatible with ie8

<a href="#001">跳到001</a> 
...文字省略 
<a name="001" id="001" > & n b s p </a> 
...文字省略


Another question, do you want to display the anchor content of a certain page (such as: 123.html)?
The code is as follows

<a href="123.html#001">跳到001</a> 
...文字省略 
<a name="001" id="001" > & n b s p </a> 
...文字省略

This is yesterday when I was working on the background. I wanted to implement "modify positioning", so I moved the anchor mark out (usually it is forgotten by me).
But the program said that to get the value, there must be "?" or "&" in the connection, so my anchor point will be incompatible...
Haha! There will be a solution in the future!
Although there is a problem with anchor point compatibility in jsp pages, there is no problem in static pages, and it is still worth learning!
3. In WEB development, page anchors will be used. HTML page anchors are used to link to a section of a page. W3School says that creating anchors uses the 3499910bf9dac5ae3c52d5ede7383485 (anchor) tag and the name attribute, but this is not the only way to create page anchors. Let’s briefly talk about two ways to make HTML page anchors.
We can use W3School's online testing tool to conduct testing. The test code after opening the link uses 64fabc9fc6232be280e37d39127ad19c and fd7787ab928c3fdea11bcb30cd63ab44, and there is no problem in the test. Then change "c1a436a314ed609750bd7c7d319db4da 48851e4b56484cc136ed2820d56732caChapter 4 5db79b134e9f6b82c0b36e0489ee08ed 2e9b454fa8428549ca2e64dfac4625cd" to "6df6139f728e20ad509be83df8b61d6aChapter 4 2e9b454fa8428549ca2e64dfac4625cd "After testing, the effect is the same.
Explanation, in addition to using the name attribute of the anchor tag when making a page anchor, you can also use the id attribute. The value of the href attribute in the anchor 3499910bf9dac5ae3c52d5ede7383485 tag is the beginning of # plus the value of the target's name or id:

Copy code

The code is as follows:

<html> 
<body> 
<p> 
<a href="#method1">页面锚点方法一</a> 
</p> 
<p> 
<a href="#method2">页面锚点方法二</a> 
</p> 
<h2><a name="method1">方法一</a></h2> 
<p>使用锚标签的 href 和 name 属性</p> 
<h2 id="method2">方法二</h2> 
<p>使用锚标签和 id 属性</p> 
</body> 
</html>

I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

What are the symbols that mark text comments in Html

How to implement an HTML-like command line interface

html+css+javascript How to implement list circular scrolling

The above is the detailed content of How to use anchors in html web pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn