HTML入门教程 - 8.链接(Links)

来源:互联网 发布:知乎 yuhang liu 编辑:程序博客网 时间:2024/05/18 21:43

 到现在为止,我们已经可以创建出一个独立的网页使用前面我们所学的知识点,确实是非常的不错,但是这一节我们学习的是链接来是你做的网页融入到网络中。

"HTML"中的”H“和”T“表示的是”hypertext“(超文本),基本上就是系统的文字链接。

锚文本(anchor tag (a))使用来定义一个链接的,但是你同样可以增加一些其他的内容来这个锚文本 - 链接的目的链接。

示例代码显示:

<!DOCTYPE html><html><head>    <title>My first web page - BESTSG</title></head><body>    <h1>My first web page</h1>    <h2>What this is</h2>    <p>A simple page put together using HTML</p>    <h2>Why this is</h2>    <p>To learn HTML</p>    <h2>Where to find the tutorial</h2>    <p><a href="http://blog.csdn.net/bestsg">BESTSG</a></p></body></html>

实际显示如下:

My first web page

What this is

A simple page put together using HTML

Why this is

To learn HTML

Where to find the tutorial

BESTSG


如上所示,链接的标签定义为“href”属性。链接可以是绝对的链接也可以是相对的链接。

绝对链接:

<a href="http://blog.csdn.net/bestsg">BESTSG</a>

相对链接:
<a href="index.html">BESTSG</a>

链接不必指向其他的HTML文件,他同样可以指向网络中的任意文件。


注意:链接同样可以发送一个用户请求去同一页面的另外一个部分。你可以在标签中增加一个“id”标签属性。
代码示例如下:
<h2 id="go">BESTSG</h2><p>xxx</p><a href="#go">Go to BESTSG</a>

当你点击这个“Go to BESTSG”的链接时,页面将会滚动到“h2 id=“go”的位置。


原创粉丝点击