Home > Web Front-end > HTML Tutorial > Detailed explanation of HTML hyperlinks

Detailed explanation of HTML hyperlinks

不言
Release: 2018-04-27 14:25:47
Original
1913 people have browsed it

This article mainly introduces the detailed explanation of HTML hyperlinks. It has certain reference value. Now I share it with everyone. Friends in need can refer to it.

Hyperlinks are HTML that are frequently used in websites. Element, because various pages of the website are connected by hyperlinks, and hyperlinks complete the jump between pages. Hyperlinks are the main means of interaction between browsers and servers, and we will gradually learn more about them in the following technologies. Hyperlink

Hyperlink is a frequently used HTML element in the website, because the various pages of the website are connected by hyperlinks, and the hyperlink completes the connection between the pages. Jump. Hyperlinks are the main means of interaction between browsers and servers, and we will gradually learn more about them in the following technologies.

— Note: Pictures can also be used as links, which will be studied in detail in the next chapter "Pictures in Web Pages".

4.5.1 Add a link to the text

The label of the hyperlink is , add a super link to the text Links are similar to other modification tags. The text after adding the link has its own special style to distinguish it from other text. The default link style is blue text with underline. A hyperlink jumps to another page. The tag has an href attribute responsible for specifying the address of the new page. The address specified by href generally uses a relative address.

— Description: In website development, document relative addresses are more commonly used.

Create a web page file in the D:\web\ directory, name it a.htm, and write the code as shown in code 4.18.

Code 4.18 Hyperlink setting: a.htm

<html>
<head>
  <title>超级链接的设置</title>
</head>
<body>
<font size="5">
<a href="ul_ol.htm">进入列表的设置页面</a>
</font>
</body>
</html>
Copy after login

Enter http://localhost/a.htm in the browser address bar, and the browsing effect is as shown in Figure 4.19.

Figure 4.19 Hyperlink settings

Readers can see the default style of hyperlinks from Figure 4.19. When clicking a link on the page, the page It will jump to the ul_ol.htm page in the same directory, which is the list setting page in the previous section. When you click the browser's "Back" button to return to the a.htm page, the color of the text link turns purple to tell the viewer that this link has been visited.

4.5.2 Modify the window opening method of the link

By default, the way a hyperlink opens a new page is to overwrite itself. According to the different needs of the browser, readers can specify other ways of opening new windows for hyperlinks. The hyperlink tag provides the target attribute for setting. The values ​​are _self (self-overwriting, default), _blank (create a new window to open a new page), _top (open in the entire window of the browser, all frame structures will be ignored) ), _parent (open in the previous window).

— Note: The _top and _parent methods are used for frame pages, and will be explained in detail in later chapters.

4.5.3 Add prompt text to the link

In many cases, the text of the hyperlink is not enough to describe the content to be linked. The hyperlink The tag provides a title attribute that can easily prompt the viewer. The value of the title attribute is the prompt content. When the viewer's cursor stays on the hyperlink, the prompt content will appear. This will not affect the neatness of the page layout. Modify the a.htm web page file and write the code as shown in code 4.19.

Code 4.19 Hyperlink setting: a.htm

<html>
<head>
  <title>超级链接的设置</title>
</head>
<body>
<font size="5">
<a href="ul_ol.htm" target="_blank" title="读者你好,现在你看到的是提示文字,单击本链接可以新开窗口跳转到ul_ol.htm页面。">进入列表的设置页面</a>
</font>
</body>
</html>
Copy after login

Enter http://localhost/a.htm in the browser address bar, and the browsing effect is as shown in Figure 4.20.

Figure 4.20 Hyperlink prompt text

## 4.5.4 What is an anchor

Many web articles have a lot of content, resulting in very long pages, and viewers need to constantly drag the browser's scroll bar to find the content they need. The anchor function of the hyperlink can solve this problem. The anchor is derived from the anchor on the ship. After the anchor is dropped, the ship will not easily drift away or get lost. In fact, anchors are used to jump to different locations within a single page. Some places are called bookmarks.

The name attribute of the hyperlink tag is used to define the name of the anchor. A page can define multiple anchors. The href attribute of the hyperlink can jump to the corresponding anchor based on the name. Create a web page file in the D:\web\ directory, name it a_anchor.htm, and write the code as shown in Code 4.20.

Code 4.20 Hyperlink anchor: a_anchor.htm

<html>
<head>
  <title>超级链接的设置</title>
</head>
<body>
<font size="5">
<a name="top">这里是顶部的锚</a><br />
<a href="#1">第1任</a><br />
<a href="#2">第2任</a><br />
<a href="#3">第3任</a><br />
<a href="#4">第4任</a><br />
<a href="#5">第5任</a><br />
<a href="#6">第6任</a><br />
<h2>美国历任总统</h2>
●第1任(1789-1797)<a name="1">这里是第1任的锚</a><br />
姓名:乔治·华盛顿<br />
George Washington<br />
生卒:1732-1799<br />
政党::联邦<br />
●第2任(1797-1801)<a name="2">这里是第2任的锚</a><br />
姓名:约翰·亚当斯<br />
John Adams<br />
生卒:1735-1826<br />
政党::联邦<br />
●第3任(1801-1809)<a name="3">这里是第3任的锚</a><br />
姓名:托马斯·杰斐逊<br />
Thomas Jefferson<br />
生卒:1743-1826<br />
政党::民共<br />
●第4任(1809-1817)<a name="4">这里是第4任的锚</a><br />
姓名:詹姆斯·麦迪逊<br />
James Madison<br />
生卒:1751-1836<br />
政党:民共<br />
●第5任(1817-1825)<a name="5">这里是第5任的锚</a><br />
姓名:詹姆斯·门罗<br />
James Monroe<br />
生卒:1758-1831<br />
政党:民共<br />
</font>
</body>
</html>l>
Copy after login

Before testing, readers can see from Code 4.20 that the tag is also used to define the anchor. , the name of the anchor is defined with the name attribute (the name is not limited and can be customized). When looking for anchor links, use the href attribute to specify the corresponding name, and add a # symbol in front of the name. Enter http://localhost/a_anchor.htm in the browser address bar, and the browsing effect is as shown in Figure 4.21.

图4.21 超级链接的锚

当浏览者单击超级链接时,页面将自动滚动到href属性值名称的锚位置。

— 注意:定义锚的标签内不一定需要具体内容,只是做一个定位。

4.5.5 电子邮件、FTP和Telnet的链接

超级链接还可以进一步扩展网页的功能,比较常用的有发电子邮件、FTP以及Telnet连接。完成以上的功能只需要修改超级链接的href值。发电子邮件的编写格式为:

<a href = "mailto:邮件地址">给我发email</a>
Copy after login

邮件地址必须完整,如intel@qq.com。

前面提到过,浏览网页采用http协议,而FTP服务器采用FTP协议连接,链接格式如下:

<a href = "ftp://服务器IP地址或域名">链接的文字</a>
Copy after login

FTP服务器链接和网页链接区别在于所用协议不同。FTP需要从服务器管理员处获得登录的权限。不过部分FTP服务器可以匿名访问,从而能获得一些公开的文件。同样,连接Telnet协议的服务器也是采用类似方法,格式如下:

<a href = "telnet://服务器IP地址或域名">链接的文字</a>
Copy after login

telnet协议应用非常少,使用http协议居多。在D:\web\目录下创建网页文件,命名为mail.htm,编写代码如代码4.21所示。

代码4.21 超级链接的其他设置:mail.htm

<html>
<head>
  <title>超级链接的其他设置</title>
</head>
<body>
<font size="5">
<a href="mailto:intel@qq.com" title="读者你好,单击这里可以发电子邮件。">给我发E-mail</a><br />
<a href="ftp://101.22.25.11" title="读者你好,欢迎进入FTP服务器。">连接FTP服务器</a><br />
<a href="telnet://101.22.25.11" title="读者你好,欢迎进入Telnet服务器。">连接Telnet服务器</a>
</font>
</body>
</html>s
Copy after login

在浏览器地址栏输入http://localhost/mail.htm,浏览效果如图4.22所示。

图4.22  超级链接的其他设置

相关推荐:

html发送邮件通过Mailto简单实现

The above is the detailed content of Detailed explanation of HTML hyperlinks. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template