<dfn>:定义元素

<dfn> HTML 元素指示要定义的术语。<dfn> 元素应该用在完整的定义语句中,其中祖级 <p> 元素、<dt>/<dd> 配对或 <dfn> 元素的最近的 <section> 祖级被认为是该术语的完整定义。

¥The <dfn> HTML element indicates a term to be defined. The <dfn> element should be used in a complete definition statement, where the ancestor <p> element, the <dt>/<dd> pairing, or the nearest <section> ancestor of the <dfn> element, is considered to be the full definition of the term.

Try it

属性

¥Attributes

该元素的属性包括 全局属性

¥This element's attributes include the global attributes.

title 属性具有特殊含义,如下所述。

¥The title attribute has special meaning, as noted below.

使用说明

¥Usage notes

使用 <dfn> 元素有一些不完全明显的方面。我们在这里检查这些。

¥There are some not-entirely-obvious aspects to using the <dfn> element. We examine those here.

指定正在定义的术语

¥Specifying the term being defined

所定义的术语是按照以下规则确定的:

¥The term being defined is identified following these rules:

  1. 如果 <dfn> 元素具有 title 属性,则 title 属性的值被视为正在定义的术语。该元素中仍必须包含文本,但该文本可以是缩写(可能使用 <abbr>)或该术语的其他形式。
  2. 如果 <dfn> 包含单个子元素并且没有自己的任何文本内容,并且该子元素是本身具有 title 属性的 <abbr> 元素,则 <abbr> 元素的 title 的确切值就是所定义的术语。
  3. 否则,<dfn> 元素的文本内容就是正在定义的术语。显示为 在下面的第一个例子中

注意:如果 <dfn> 元素具有 title 属性,则它必须包含正在定义的术语,并且不得包含其他文本。

¥Note: If the <dfn> element has a title attribute, it must contain the term being defined and no other text.

<dfn> 元素的链接

¥Links to <dfn> elements

如果你在 <dfn> 元素上包含 id 属性,则可以使用 <a> 元素链接到它。此类链接应该是该术语的使用,目的是读者可以通过单击该术语的链接快速导航到该术语的定义(如果他们还不知道)。

¥If you include an id attribute on the <dfn> element, you can then link to it using <a> elements. Such links should be uses of the term, with the intent being that the reader can quickly navigate to the term's definition if they're not already aware of it, by clicking on the term's link.

这如下面 定义链接 下的示例所示。

¥This is shown in the example under Links to definitions below.

示例

¥Examples

让我们看一下各种使用场景的一些示例。

¥Let's take a look at some examples of various usage scenarios.

术语的基本识别

¥Basic identification of a term

此示例使用纯 <dfn> 元素来标识术语在定义中的位置。

¥This example uses a plain <dfn> element to identify the location of a term within the definition.

HTML

html
<p>
  The <strong>HTML Definition element (<dfn>&lt;dfn&gt;</dfn>)</strong> is used
  to indicate the term being defined within the context of a definition phrase
  or sentence.
</p>

由于 <dfn> 元素没有 title,因此 <dfn> 元素本身的文本内容用作所定义的术语。

¥Since the <dfn> element has no title, the text contents of the <dfn> element itself are used as the term being defined.

结果

¥Result

定义链接

¥Links to definitions

要向定义添加链接,你可以像往常一样使用 <a> 元素创建链接。

¥To add links to the definitions, you create the link the same way you always do, with the <a> element.

HTML

html
<p>
  The
  <strong>HTML Definition element (<dfn id="definition-dfn">&lt;dfn&gt;</dfn>)</strong>
  is used to indicate the term being defined within the context of a definition
  phrase or sentence.
</p>

<p>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Graece donan, Latine
  voluptatem vocant. Confecta res esset. Duo Reges: constructio interrete.
  Scrupulum, inquam, abeunti;
</p>

<p>
  Because of all of that, we decided to use the
  <code><a href="#definition-dfn">&lt;dfn&gt;</a></code> element for this
  project.
</p>

这里我们看到了定义 - 现在有一个 id 属性,"definition-dfn",它可以用作链接的目标。随后,使用 <a> 创建链接,并将 href 属性设置为 "#definition-dfn",以设置返回到定义的链接。

¥Here we see the definition — now with an id attribute, "definition-dfn", which can be used as the target of a link. Later on, a link is created using <a> with the href attribute set to "#definition-dfn" to set up the link back to the definition.

结果

¥Result

一起使用缩写和定义

¥Using abbreviations and definitions together

在某些情况下,你可能希望在定义术语时使用术语的缩写。这可以通过串联使用 <dfn><abbr> 元素来完成,如下所示:

¥In some cases, you may wish to use an abbreviation for a term when defining it. This can be done by using the <dfn> and <abbr> elements in tandem, like this:

HTML

html
<p>
  The <dfn><abbr title="Hubble Space Telescope">HST</abbr></dfn> is among the
  most productive scientific instruments ever constructed. It has been in orbit
  for over 20 years, scanning the sky and returning data and photographs of
  unprecedented quality and detail.
</p>

<p>
  Indeed, the <abbr title="Hubble Space Telescope">HST</abbr> has arguably done
  more to advance science than any device ever built.
</p>

请注意嵌套在 <dfn> 内的 <abbr> 元素。前者确定该术语是缩写 ("HST"),并在其 title 属性中指定完整术语 ("哈勃太空望远镜")。后者表明缩写术语代表正在定义的术语。

¥Note the <abbr> element nested inside the <dfn>. The former establishes that the term is an abbreviation ("HST") and specifies the full term ("Hubble Space Telescope") in its title attribute. The latter indicates that the abbreviated term represents a term being defined.

结果

¥Result

技术总结

¥Technical summary

内容类别 流量内容措辞内容,可触及的内容。
允许的内容 措辞内容,但 <dfn> 元素不一定是后代。
标签遗漏 无,开始和结束标记都是强制性的。
允许的父级 任何接受 措辞内容 的元素。
隐式 ARIA 角色 term
允许的 ARIA 角色 任何
DOM 接口 HTMLElement

规范

Specification
HTML Standard
# the-dfn-element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also