对技术上不是段落的文本使用 <p> 在语义上是否正确
Is it semantically correct to use a <p> for text that technically is not a paragraph
更常见的是,当我为网站编写标记时,只要出现任何形式的文本,我就会使用 <p>
标签。是否是博客上的一段post
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam eget mattis enim. Ut tempus pulvinar est et consectetur.
Sed malesuada ex et augue vulputate congue sit amet ut nunc.
</p>
或者是一小段信息,例如页脚中的地址、页眉中的 phone 数字,甚至是警告消息。
<p>0191 482 4003</p>
<p>123 Random Address Road</p>
<p>Wait! An error has occurred.</p>
从技术上讲,我不认为这些是 'paragraphs' 文本,而是具有特定上下文的小片段。
这条经验法则也有例外。例如,如果文本内容是时间(例如,在时钟小部件中),我会使用 <time>
小部件。
是否有更多 'semantically correct' 方式来显示技术上不是段落的文本?也许在某些情况下更具体的 HTML 标签,例如 <time>
标签?
元素的语义由 html 规范描述。我认为可以公平地说语义上正确的用法是与规范中的内容一致的用法。
有两个 html 规范,但在本例中,它们提供了完全相同的段落描述:
A paragraph is typically a run of phrasing content that forms a block of text with one or more sentences that discuss a particular topic, as in typography, but can also be used for more general thematic grouping. For instance, an address is also a paragraph, as is a part of a form, a byline, or a stanza in a poem.
https://html.spec.whatwg.org/multipage/dom.html#paragraphs, https://www.w3.org/TR/html5/dom.html#paragraphs
您提供的示例符合该描述,因此我认为它们在语义上是正确的用法。
然而,关于页眉中的 phone 数字或页脚中的地址,事实证明可能存在语义上更正确的元素。
地址元素:
The address element represents the contact information for its nearest article or body element ancestor. If that is the body element, then the contact information applies to the document as a whole.
https://html.spec.whatwg.org/multipage/sections.html#the-address-element, https://www.w3.org/TR/html5/sections.html#the-address-element
<address></address>
例如,如果您要创建一个关于地址历史的网页,您可以在正文中使用段落标签来展示历史地址,但在 header/footer 中您可以使用地址标签来展示历史地址将您的联系信息标记为页面作者。
更常见的是,当我为网站编写标记时,只要出现任何形式的文本,我就会使用 <p>
标签。是否是博客上的一段post
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam eget mattis enim. Ut tempus pulvinar est et consectetur.
Sed malesuada ex et augue vulputate congue sit amet ut nunc.
</p>
或者是一小段信息,例如页脚中的地址、页眉中的 phone 数字,甚至是警告消息。
<p>0191 482 4003</p>
<p>123 Random Address Road</p>
<p>Wait! An error has occurred.</p>
从技术上讲,我不认为这些是 'paragraphs' 文本,而是具有特定上下文的小片段。
这条经验法则也有例外。例如,如果文本内容是时间(例如,在时钟小部件中),我会使用 <time>
小部件。
是否有更多 'semantically correct' 方式来显示技术上不是段落的文本?也许在某些情况下更具体的 HTML 标签,例如 <time>
标签?
元素的语义由 html 规范描述。我认为可以公平地说语义上正确的用法是与规范中的内容一致的用法。
有两个 html 规范,但在本例中,它们提供了完全相同的段落描述:
A paragraph is typically a run of phrasing content that forms a block of text with one or more sentences that discuss a particular topic, as in typography, but can also be used for more general thematic grouping. For instance, an address is also a paragraph, as is a part of a form, a byline, or a stanza in a poem. https://html.spec.whatwg.org/multipage/dom.html#paragraphs, https://www.w3.org/TR/html5/dom.html#paragraphs
您提供的示例符合该描述,因此我认为它们在语义上是正确的用法。
然而,关于页眉中的 phone 数字或页脚中的地址,事实证明可能存在语义上更正确的元素。
地址元素:
The address element represents the contact information for its nearest article or body element ancestor. If that is the body element, then the contact information applies to the document as a whole. https://html.spec.whatwg.org/multipage/sections.html#the-address-element, https://www.w3.org/TR/html5/sections.html#the-address-element
<address></address>
例如,如果您要创建一个关于地址历史的网页,您可以在正文中使用段落标签来展示历史地址,但在 header/footer 中您可以使用地址标签来展示历史地址将您的联系信息标记为页面作者。