何时使用< span>改为< p> ;? [英] When to use <span> instead <p>?
问题描述
正如问题所示,如果我在HTML中添加了一些文本,那么何时应该使用< p>
以及何时应该使用< span>
?
打算描述它包含的内容。
所以,如果你想传达一个段落,那就这样做。
<虽然你的比较并不完全正确。比较直接的比较是
何时使用
< div>
作为块级元素,< p>
?
$ b
A 有时候,当对事物进行样式化时,一个< span>
内联,非常像锚点(< a> ; ),
非常适合给你一些东西钩住CSS,但它是一个没有语义或文体意义的空标签。< strong>
,重点(< em>
)等。因此,请记住,由于它在html和自然写作中都是默认属性,所以段落会在它自身之前和之后导致中断,如< div>
。
As the question indicates, if I have some text that I want to add in the HTML then when should I use <p>
and when should I use <span>
?
You should keep in mind, that HTML is intended to DESCRIBE the content it contains.
So, if you wish to convey a paragraph, then do so.
Your comparison isn't exactly right, though. The more direct comparison would be
When to use a
<div>
instead of a<p>
?
as both are block level elements.
A <span>
is inline, much like an anchor (<a>
), <strong>
, emphasis (<em>
), etc., so bear in mind that by it's default nature in both html and in natural writing, that a paragraph will cause a break before and after itself, like a <div>
.
Sometimes, when styling things — inline things — a <span>
is great to give you something to "hook" the css to, but it is otherwise an empty tag devoid of semantic or stylistic meaning.
这篇关于何时使用< span>改为< p> ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!