我应该使用& lt; p& gt;或" span& gt;一行文字的元素? [英] Should I use <p> or <span> element for a single line of text?

查看:85
本文介绍了我应该使用& lt; p& gt;或" span& gt;一行文字的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我读过某处某行文本被认为是一个段落,因此可以有效地放置在"代表文本的一个段落/块的< p> 元素中".

Sometime ago I read somewhere that one single line of text is considered a paragraph, therefore valid to be placed into a <p> element that "represents a paragraph/block of text".

我刚刚发现的一些例子证实了浏览此内容的可能性:

Browsing around this is confirmed by some examples that I've just found:

http://www.w3.org/wiki/HTML/Elements/p#Example_A

http://reference.sitepoint.com/html/p

在我的特定情况下,我正在制作一个< form> ,其中包含每个字段的一些验证消息,并且仅在用户与页面互动时才对用户有意义.

In my particular case I am making a <form> that includes some validation messages for each field and that are only meaningful to the user once they interact with the page.

出于定位目的(< p> 是一个块元素),对于这些消息,更容易使用< p> 元素,但是由于< span> 是一个更通用且毫无意义的元素,我也可以将其与"display:block" 一起使用,但是我不确定是否应该这样做.

For positioning purposes (<p> is a block element) would be easier to use <p> elements for these messages, but since <span> is a more generic and meaningless element I could use it too with "display:block" but I am not sure if I should do this instead.

您能告诉我在这种情况下要使用什么元素吗?

Could you tell me what is the element to be used in this case?.

谢谢!

推荐答案

HTML5规范定义了

The HTML5 spec defines that the p element "represents a paragraph", and a paragraph is defined as:

段落通常是一系列措辞内容,它们与一个或多个讨论特定主题的句子一起形成文本块,如在印刷术中一样,但也可用于更一般的主题分组.例如,一个地址也就是一个段落,就像一首诗中的表格,下划线或节中的一部分一样.

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.

通常,没有人可以回答是否应该使用 p ,这取决于每个特定的情况以及您对内容的理解.

No-one can generally answer if you should use p or not, this depends on each particular case, and also your understanding of the content.

现在,如果您认为 p 可能不合适,为什么要使用 div .

Now, if you think p may not be appropriate, why do you want to go with span when you are looking for a block element? Just use div instead.

这篇关于我应该使用&amp; lt; p&amp; gt;或&quot; span&amp; gt;一行文字的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆