链接

本文详细介绍了如何在HTML中创建指向其他网页的链接,以及如何创建内部锚点进行页面内的跳转。通过示例代码,展示了如何使用`<a>`标签设置`href`和`title`属性,以及如何通过`id`属性创建锚点并链接到它们。强调了HTML5允许在链接中包含多种元素,并解释了锚点链接不工作可能的原因和解决方案。
摘要由CSDN通过智能技术生成

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 在一个
页面中只存在一次
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pk5515

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值