在< p>内嵌入块级元素标签...对错还是错? [英] Nesting block level elements inside the <p> tag... right or wrong?
问题描述
在语法和语义上是否正确嵌套< p> $ c>中的任何其他块级别元素
< div>
$ c>标记。
如果没有,那么可以使用< span style =display:block> c >
p
在所有HTML标准中无效。此外,当使用合格的HTML解析器时,不可能在< p> $ c $中放置
< div>
c>,因为开头< div>
标签将自动关闭< p>
元素。
语义上,正确的选择取决于您标记的内容。您将需要至少显示一个示例完整段落以及可能的周围内容,以确保提供足够的信息,以确定正确的语义标记。
但是,由于< div>
和< span>
都是语义自由的,如果你确定< p>
标签的内容真正形成一个段落,并且< span style = display:block>
获得您所寻求的表现效果,那么这是有效的HTML,将是一个完全合适的解决方案。
Is it syntactically and semantically correct to nest <div>
or any other block level element inside the <p>
tag. I am talking about HTML4 Transitional DTD.
If not then is it OK to instead use <span style="display: block">
instead?
Syntactically, a div
inside a p
is invalid in all standards of HTML. Moreover, when using a conforming HTML parser, it is impossible to place a <div>
element inside a <p>
in the DOM because the opening <div>
tag will automatically close the <p>
element.
Semantically, the correct choice depends on the content that you are marking up. You will need to show at least a sample full paragraph and possibly the content surrounding it to be sure of providing sufficient information for the correct semantic mark-up to be determined.
However, given that both <div>
and <span>
are semantics free, and that CSS in no way can ever change that, if you are certain that the contents of the <p>
tag truly form a paragraph, and that <span style="display: block">
gets you the presentational effect that you are seeking, then that is valid HTML and would be a wholly appropriate solution.
这篇关于在< p>内嵌入块级元素标签...对错还是错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!