<dfn>:定義元素
<dfn> HTML 元素指示要定義的術語。<dfn> 元素應在完整的定義語句中使用,其中術語的完整定義可以是以下之一
試一試
屬性
此元素的屬性包括 全域性屬性。
title 屬性具有特殊含義,如下所述。
使用說明
使用 <dfn> 元素有一些不太明顯的方面。我們在這裡對此進行探討。
指定要定義的術語
到 <dfn> 元素的連結
示例
讓我們來看一些不同使用場景的示例。
術語的基本識別
此示例使用簡單的 <dfn> 元素來識別定義中術語的位置。
HTML
html
<p>
The <strong>HTML Definition element (<dfn><dfn></dfn>)</strong> is used
to indicate the term being defined within the context of a definition phrase
or sentence.
</p>
由於 <dfn> 元素沒有 title,因此 <dfn> 元素本身的文字內容用作要定義的術語。
結果
連結到定義
要新增指向定義的連結,您可以像往常一樣建立連結,使用 <a> 元素。
HTML
html
<p>
The
<strong>HTML Definition element (<dfn id="definition-dfn"><dfn></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"><dfn></a></code> element for this
project.
</p>
在這裡,我們看到了定義——現在具有 id 屬性 "definition-dfn",它可以用作連結的目標。稍後,使用 <a> 建立一個連結,其 href 屬性設定為 "#definition-dfn" 以建立返回定義的連結。
結果
將縮寫和定義一起使用
在某些情況下,您可能希望在定義術語時使用其縮寫。這可以透過像這樣一起使用 <dfn> 和 <abbr> 元素來完成
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 屬性中指定了完整術語(“哈勃太空望遠鏡”)。後者表示縮寫術語代表要定義的術語。
結果
技術摘要
規範
| 規範 |
|---|
| HTML 標準 # the-dfn-element |
瀏覽器相容性
BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。