浏览器通常会为其文本元素添加不同的样式,以区别于普通文本。例如 em 和 cite 元素中的文本都是斜体的。又如,code 元素专门用来格式化脚本或程序中的代码,该元素中的文本默认使用等宽字体。内容显示的样子与其使用的标记没有关系。因此不应该为了让文字变为斜体就使用 em 或 cite,添加样式是 css 的事情。相反,应该选择能描述内容的 HTML 元素。
1.创建锚: 输入 id=”anchor-name”,其中 name 是在内部用来标识网页中这部分内容的文字。
2.创建锚链接到特定锚链接:输入 ,其中 anchor-name 是目标的 id 属性值。
3.输入标签文本(默认带下划线蓝色字体),用户激活该字体时将用户带到(1)步中引用的区域文本。
```
Creating and Linking to Anchors
Frequently Asked Questions (FAQ)
Can an id have more than one word?
Yes, your ids can have more than one word as long as there are no spaces. Separate each word with a dash instead.
Can visitors bookmark anchor links?
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.
My anchor link isn't working. What am I doing wrong?
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 is preceded by "#" and that it matches the anchor id.
How do I link to a specific part of someone else's webpage?
Although you obviously can't add anchors to other people's pages, you can take advantage of the ones that they have already created. View the source code of their webpage to see if they've included an id on the part of the page you want to link to. (For help viewing source code, consult "The Inspiration of Others" in Chapter 2.) Then create a link that includes the anchor.