在span内显示类似于p的元素? [英] Displaying an element similar to p inside a span?
问题描述
我有一个范围与一个inculded p,像这样:
I have a span with an inculded p, like this:
<span>
<p>this is the p</p>
</span>
根据HTML5规范,这是不允许的。现在,我的HTML比上面更复杂,我需要一个类似于我可以使用的p。我可以使用哪个标签或者我可以使用css更改哪个元素,所以它的行为像ap?
This is not allowed according to the HTML5 specs. Now, my HTML is more complex than the above and I need something similar to a p which I can use instead. Which tag could I use or which element can I change using css so it behaves like a p?
推荐答案
p
有一个意义。
如果您的内容符合 p
的定义,您应该使用 p
。那么你应该使用 div
而不是 span
(除非没有其他合适的候选者):
If your content matches p
’s definition, you should use p
. Then you should use a div
instead of a span
(unless there is no other suitable candidate):
<div>
<p>…</p>
</div>
如果您的内容不符合 p
的定义,你不应该使用 p
。然后,您可以使用 span
而不是 p
(如果没有其他合适的候选人):
If your content doesn’t match p
’s definition, you shouldn’t use p
. Then you could use span
instead of p
(if there is no other suitable candidate):
<span>
<span>…</span>
</span>
span
div 没有任何意义。所以你只需要考虑在哪里他们是语法放置(块与内联)。您可以互换,而不会丢失/更改任何语义:
span
and div
don’t have meanings. So you only have to consider where they are placed syntactically (block vs. inline). You can swap them without losing/changing any semantics:
<div>
<span>…</span>
</div>
<div>
<div>…</div>
</div>
请注意,这些与这些元素的样式没有任何关系。您可以使用CSS为块级元素设置样式,以使其显示为内联,反之亦然: display:inline;
display:block;
。
Note that all this doesn’t have anything to do with how these elements are styled. You can style a block-level element with CSS so that it appears as inline and vice-versa: display:inline;
resp. display:block;
.
这篇关于在span内显示类似于p的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!