Html HTML5 链接到部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14542592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:16:38  来源:igfitidea点击:

HTML5 Link to section

html

提问by adrian

Well, in HTML 4.01 with for example <div id="example">I could make <a href="#example">to scroll to that div.

好吧,在 HTML 4.01 中,例如<div id="example">我可以<a href="#example">滚动到那个 div。

How can I make the same effect with <section class="asd xyz">?

我怎样才能产生同样的效果<section class="asd xyz">

回答by thordarson

They work the same. Add an ID to the section and the link should work.

它们的工作原理相同。向该部分添加一个 ID,链接应该可以工作。

<section id="example"></section>

This code jumps to the section #example.

此代码跳转到部分#example

<a href="#example">Jump to example</a>

EDIT:Pure HTML does not allow you to jump to class names and for a good reason. IDs are unique while classes can be reused as often as you want. Therefore you just can't jump to a class name since it probably doesn't have a single target.

编辑:纯 HTML 不允许您跳转到类名,这是有充分理由的。ID 是唯一的,而类可以根据需要多次重复使用。因此你不能跳转到一个类名,因为它可能没有一个单一的目标。