HTML link 关系如何与片段标识符相关?
How do HTML link relations relate to fragment identifiers?
有时,我们使用 rel
属性将 link 的含义传达给特定页面或页面片段,例如:
<link rel="author" href="https://example.com/humans.txt">
<a rel="bookmark" href="https://example.com/page#thing">thing</a>
到目前为止,还不错。
案例
现在假设我有一个词汇表页面,https://example.com/glossary
,在该页面上,我有一个包含大量术语的定义列表:
<dl id="dictionary">
<dt id="foo">foo</dt>
<dd>A foo is not a <a href="#bar">bar</a>.</dd>
<dt id="bar">bar</dt>
<dd>A metric unit of pressure that serves alcoholic beverages.</dd>
</dl>
这让我们想知道 proper/best 到词汇表以及所述词汇表中的特定术语的 link 方法是什么。我想出了以下选项:
词汇表:
1. <link rel="glossary" href="https://example.com/glossary">
2. <link rel="glossary" href="https://example.com/glossary#dictionary">
对于特定术语:
1. <a rel="bookmark" href="https://example.com/glossary#bar">bar</a>
2. <a rel="glossary" href="https://example.com/glossary#bar">bar</a>
3. <a rel="bookmark glossary" href="https://example.com/glossary#bar">bar</a>
4. <a href="https://example.com/glossary#bar">bar</a>
您认为最好的选择是什么,为什么?请注意,完全有可能最好的方法是我没有考虑过的。
glossary
link类型指的是"a document providing a glossary of terms that pertain to the current document"。
bookmark
link类型给出最近的祖先article
的permalink,如果有none,对于最近的祖先 section.
因此,当您 link 为博客 post(或类似)中出现的术语定义术语时,您不得使用 bookmark
类型,否则此博客 post 的 permalink 将是术语定义的 URL。但由于博客 post 包含词汇表中定义的术语,您可以 link 使用 glossary
link 类型的词汇表。
<!DOCTYPE html>
<title>Blog post that contains a term defined in the glossary</title>
<link rel="glossary" href="/glossary" />
<article>
<p>The <a href="/glossary#foo">foo</a> is great.</p>
</article>
为 glossary
提供片段标识符应该不会有什么坏处,在某些情况下甚至需要这样做:例如,当需要片段标识符来显示词汇表时,或者当文档包含其他内容时词汇表之外的主要内容。
注意:您可以在 dt
元素中使用 dfn
元素,并将 id
属性移动到 dfn
元素。
<dl id="dictionary">
<dt><dfn id="foo">foo</dfn></dt>
<dd>A foo is not a <a href="#bar">bar</a>.</dd>
</dl>
您可能还对添加结构化数据感兴趣,。
有时,我们使用 rel
属性将 link 的含义传达给特定页面或页面片段,例如:
<link rel="author" href="https://example.com/humans.txt">
<a rel="bookmark" href="https://example.com/page#thing">thing</a>
到目前为止,还不错。
案例
现在假设我有一个词汇表页面,https://example.com/glossary
,在该页面上,我有一个包含大量术语的定义列表:
<dl id="dictionary">
<dt id="foo">foo</dt>
<dd>A foo is not a <a href="#bar">bar</a>.</dd>
<dt id="bar">bar</dt>
<dd>A metric unit of pressure that serves alcoholic beverages.</dd>
</dl>
这让我们想知道 proper/best 到词汇表以及所述词汇表中的特定术语的 link 方法是什么。我想出了以下选项:
词汇表:
1. <link rel="glossary" href="https://example.com/glossary">
2. <link rel="glossary" href="https://example.com/glossary#dictionary">
对于特定术语:
1. <a rel="bookmark" href="https://example.com/glossary#bar">bar</a>
2. <a rel="glossary" href="https://example.com/glossary#bar">bar</a>
3. <a rel="bookmark glossary" href="https://example.com/glossary#bar">bar</a>
4. <a href="https://example.com/glossary#bar">bar</a>
您认为最好的选择是什么,为什么?请注意,完全有可能最好的方法是我没有考虑过的。
glossary
link类型指的是"a document providing a glossary of terms that pertain to the current document"。
bookmark
link类型给出最近的祖先article
的permalink,如果有none,对于最近的祖先 section.
因此,当您 link 为博客 post(或类似)中出现的术语定义术语时,您不得使用 bookmark
类型,否则此博客 post 的 permalink 将是术语定义的 URL。但由于博客 post 包含词汇表中定义的术语,您可以 link 使用 glossary
link 类型的词汇表。
<!DOCTYPE html>
<title>Blog post that contains a term defined in the glossary</title>
<link rel="glossary" href="/glossary" />
<article>
<p>The <a href="/glossary#foo">foo</a> is great.</p>
</article>
为 glossary
提供片段标识符应该不会有什么坏处,在某些情况下甚至需要这样做:例如,当需要片段标识符来显示词汇表时,或者当文档包含其他内容时词汇表之外的主要内容。
注意:您可以在 dt
元素中使用 dfn
元素,并将 id
属性移动到 dfn
元素。
<dl id="dictionary">
<dt><dfn id="foo">foo</dfn></dt>
<dd>A foo is not a <a href="#bar">bar</a>.</dd>
</dl>
您可能还对添加结构化数据感兴趣,