gpt4 book ai didi

html - 片段链接失效

转载 作者:行者123 更新时间:2023-12-04 14:38:51 32 4
gpt4 key购买 nike

完全是新手问题,但我不知道我做错了什么。我想要一个跳转到页面标题的链接。我相信这些被称为片段链接。这是我的代码不起作用:

<a href="#Frag">My Link</a>

<div id="cont">

<p>Lots of content here, abbreviated in this example to save space</p>

<h2 id="Frag">Header I want to jump to</h2>
</div>

最佳答案

很确定您需要指定 name anchor 工作的属性,例如:

<a href="#content">Skip to content</a>

<div name="content" id="content"></div>

好吧,“非常确定”是“猜测”的委婉说法,我想我会查一下,所以,从 HTML 4.01 Specification我们从 section 12.2.3 Anchors with the id attribute 得到这个:

The id attribute may be used to create an anchor at the start tag of any element (including the A element). This example illustrates the use of the id attribute to position an anchor in an H2 element. The anchor is linked to via the A element.

You may read more about this in <A href="#section2">Section Two</A>.

...later in the document

<H2 id="section2">Section Two</H2>

...later in the document

<P>Please refer to <A href="#section2">Section Two</A> above for more details.`

按照惯例进行猜测,也许您的页面不够长,无法跳转到该内容(也就是说,您的页面可能无处可跳转,也无处可跳转的内容to 已经可见。)

除此之外,从之前链接的规范的同一部分,这里有一些关于何时使用 what 作为 anchor 标识符(就链接本身而言)的一般信息,这些信息在其他方面可能很有值(value):

Use id or name? Authors should consider the following issues when deciding whether to use id or name for an anchor name:

  • The id attribute can act as more than just an anchor name (e.g., style sheet selector, processing identifier, etc.).
  • Some older user agents don't support anchors created with the id attribute.
  • The name attribute allows richer anchor names (with entities).

关于html - 片段链接失效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9787291/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com