Html 链接到网页的某个部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8424785/
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
Link to a section of a webpage
提问by Josh I
I want to make a link that when clicked, sends you to a certain line on the page (or another page). I know this is possible, but how do I do it?
我想制作一个链接,点击后会将您发送到页面(或其他页面)上的某一行。我知道这是可能的,但我该怎么做?
回答by Daniel Hunter
your jump link looks like this
你的跳转链接看起来像这样
<a href="#div_id">jump link</a>
Then make
然后使
<div id="div_id"></div>
the jump link will take you to that div
跳转链接将带你到那个 div
回答by bozdoz
Hashtags at the end of the URL bring a visitor to the element with the the ID: e.g.
URL 末尾的主题标签将访问者带到具有 ID 的元素:例如
http://stackoverflow.com/questions/8424785/link-to-a-section-of-a-webpage#answers
Would bring you to where the DIV with the ID 'answers' begins. Also, you can use the name attribute in anchor tags, to create the same effect.
将带您到 ID 为“答案”的 DIV 开始的位置。此外,您可以在锚标记中使用 name 属性来创建相同的效果。
回答by Kevin M
The fragment identifier (also known as: Fragment IDs, Anchor Identifiers, Named Anchors) introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document.
由井号 # 引入的片段标识符(也称为:片段 ID、锚标识符、命名锚)是文档 URL 的可选最后部分。它通常用于标识该文档的一部分。
<a href="http://www.someuri.com/page#fragment">Link to fragment identifier</a>
Syntax for URIs also allows an optional query part introduced by a question mark ?. In URIs with a query and a fragment the fragment follows the query.
URI 的语法还允许使用问号 ? 引入的可选查询部分。在带有查询和片段的 URI 中,片段跟随查询。
<a href="http://www.someuri.com/page?query=1#fragment">Link to fragment with a query</a>
When a Web browser requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent (Web browser) processes the resource according to the document type and fragment value.
当 Web 浏览器从 Web 服务器请求资源时,代理将 URI 发送到服务器,但不发送片段。相反,代理等待服务器发送资源,然后代理(Web 浏览器)根据文档类型和片段值处理资源。
Named Anchors <a name="fragment">
are deprecated in XHTML 1.0, the ID attribute is the suggested replacement. <div id="fragment"></div>
<a name="fragment">
XHTML 1.0 中不推荐使用命名锚点,建议替换 ID 属性。<div id="fragment"></div>
回答by Marc D
Simple:
简单的:
Use <section>
.
使用<section>
.
and use <a href="page.html#tips">Visit the Useful Tips Section</a>
并使用 <a href="page.html#tips">Visit the Useful Tips Section</a>