文本:缩写、引用和代码
在《HTML 初学者教程》中,我们已经涵盖了使用段落(以及强调和换行)和标题定义文本的基础知识。出于同样的原因,我们使用p 和h1、h2 等标签,还有许多其他标签也应该使用,以专门表示其他文本类型,例如缩写、引用和计算机代码。
缩写
abbr 用于标记缩写,即单词或短语的缩短形式。
缩写所代表的完整短语可以在 title 属性的值中定义。这是可选的,但推荐这样做。
<p>This web site is about <abbr title="HyperText Markup Language">HTML</abbr> and <abbr title="Cascading Style Sheets">CSS</abbr>.</p>
引用
blockquote 和q 用于引用。一般而言,blockquote 用于独立的、通常是多行的引用,而q 用于较短的、行内的引用。
如果引用的来源可以在网上找到,则可以使用 cite 属性指向其来源。
<p>So I asked Bob about quotations on the Web and he said <q>I know as much about quotations as I do about pigeon fancying</q>. Luckily, I found HTML Dog and it said:</p>
<blockquote cite="https://htmldog.cn/guides/html/intermediate/text/">
<p>blockquote and q are used for quotations. blockquote is generally used for standalone often multi-line quotations whereas q is used for shorter, in-line quotations.</p>
</blockquote>
引文
为了让事情变得更加令人困惑,除了 cite 属性之外,还有一个cite 标签。该标签可用于定义作品的标题,例如书籍。
<p>According to <cite>the Bible</cite>, after six days God said <q>screw this for a lark, I'm having a nap</q>.</p>
代码
code 用于表示任何形式的计算机代码。此外,var 可用于表示变量(这可以是任何东西中的变量,不仅仅是代码中的变量——例如,它可以是方程中的变量),samp 用于表示示例输出,而kbd(键盘)用于表示用户输入。
<p>If you add the line <code><var>givevaderachuckle</var> = true;</code> to the <code>destroy_planet</code> subroutine and then type <kbd>ilovejabba</kbd> into the console, the big bad green Death Star laser will etch <samp>Slug Lover!</samp> on the planet's surface.</p>
预格式化文本
pre 是预格式化文本,它在 HTML 标签中比较特殊,因为它会注意其中的每个字符,包括空白字符(而其他元素会忽略连续的空格或换行符,例如)。它最常用于代码块,因为其中的间距(如缩进)可能很重要。
<pre><code>
<div id="intro">
<h1>Some heading</h1>
<p>Some paragraph paragraph thing thing thingy.</p>
</div>
</code></pre>
