6.1 创建指向另一个网页的链接
<a href="cats.html" title="cat">Cookie and Woody</a>
href:规定链接指向的页面的 URL。
title:鼠标放在链接上会显示的文本
中间是内容
HTML5 几乎允许在链接内包含任何类型的元素或元素组。例如段落、列表、图像、整篇文章和区块——几乎任何元素都行(但其他链接、音频、视频、表单元素、iframe等交互式内容除外),这些元素大部分为块级元素。
创建锚并链接到锚
<body>
<article>
<header>
<h1>Frequently Asked Questions (FAQ)</h1>
<nav>
<ul>
<li><a href="#question-01">Can an id have more than word?</a></li>
<li><a href="#question-02">Can visitors bookmark anchor links?</a></li>
<li><a href="#question-03">My anchor link isn't working. What am I doing wrong?</a></li>
...
</ul>
</nav>
</header>
<h2 id="question-01">Can an id have more than word?</h2>
<p>Yes, your ids can have more than one word as long as there are no spaces. Separate each word
➝ with a dash instead.</p>
<h2 id="question-02">Can visitors bookmark anchor links?</h2>
<p>Yes, they can! And when they visit that link, the browser will jump down to the anchor as
➝ expected. Visitors can share the link with others, too, so all the more reason to choose
➝ meaningful anchor names.</p>
<h2 id="question-03">My anchor link isn't working. What am I doing wrong?</h2>
<p>The problem could be a few things. First, double-check that you added an id (without "#") to
➝ the element your link should point to. Also, be sure that the anchor in your link <em>is</em>
➝ preceded by "#" and that it matches the anchor id.</p>
...
</article>
</body>
每个以 # 开头的链接 href 值都指向拥有相应 id(不含 #)的元素。例如,<a href="#question-03">...</a> 指向 <h2 id="question-03">...</h2>。可以为任何元素指定 id,只要任何给定的 id 在一个
页面中只存在一次