问题描述
有时候,我读过某处某行文本被认为是一个段落,因此可以有效地放置在"代表文本的一个段落/块的< 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规范定义了 p
元素代表一个段落"和一个段落定义为:
The HTML5 spec defines that the p
element "represents a paragraph", and a paragraph is defined as:
通常,没有人可以回答是否应该使用 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
可能不合适,为什么要使用 span
当您在寻找一个块元素时?只需使用 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.
这篇关于我应该使用& lt; p& gt;或" span& gt;一行文字的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!