嵌套 <p>嵌套 <div> 时不起作用将要? [英] Nesting <p> won't work while nesting <div> will?
问题描述
我通常不会像这样嵌套<p>
:
以下内容:<p>一个</p><p>二</p></p>
我会使用
<p>
但似乎 Emacs 和 Google Chrome 都会认为外部 <p>
一旦看到新的 >
开始.(DOCTYPE
是 HTML 4.01 Strict).我认为 <p>
只不过是一个
不能嵌套?如果是这样,什么规则说它不能?因为一个段落就是一个段落 .. 这就是 HTML 的定义方式(而 HTML 不是 XML).
任何 代码>. 根据 9.3.1 段落:P 元素 HTML 4.01 规范: P 元素代表一个段落.它不能包含块级元素(包括 P 本身). <小时> 请注意,这是解析 HTML 的方式,即使是 但是,带有 也就是说,在 HTML 处理的这个阶段,CSS 无关,并且在确定元素是否为块时,CSS 与 DOM/解析器无关 -级别元素与否.考虑动态应用 CSS 或通过尚未加载的样式表应用 CSS 的情况:应用的 CSS 不会改变 DOM. 虽然 HTML5(工作草案)规范没有在 HTML4 规范中包含上述语言,但它确实继续将段落定义为 分阶段内容 并且还有一个关于段落的部分. HTML5 列表的公认答案元素可以嵌套在 P 元素中吗? 表示 某些元素的解析方式有些古怪(通常是出于历史原因),并且它们的内容模型限制旨在避免将作者暴露在这些问题中. 此行为引用自 关于流内容的 HTML5 WG 维基条目: HTML5 对 p 元素的嵌套以及 p 元素可能包含的内容的限制是由于引用:解析器的特殊性"导致 p 自动关闭 .. I usually won't nest and I will nest like that using I thought Because a paragraph is a paragraph .. and that's how HTML is defined (and HTML is not XML). Any Per 9.3.1 Paragraphs: the P element of the HTML 4.01 specification: The P element represents a paragraph. It cannot contain block-level elements (including P itself).
Note that this is how the HTML is parsed and that even a However, a That is, the CSS is irrelevant at this stage of the HTML processing and the CSS is irrelevant to the DOM/parser when determining if an element is a block-level element or not. Consider the case when CSS is applied dynamically or through a not-yet-loaded-stylesheet: the applied CSS does not alter the DOM. While the HTML5 (working-draft) specification does not include the language above in the HTML4 specification, it does go on to define a paragraph as a container for phasing content and further has a section on paragraphs. The accepted answer to List of HTML5 elements that can be nested inside P element? says that Certain elements are parsed in somewhat eccentric ways (typically for historical reasons), and their content model restrictions are intended to avoid exposing the author to these issues. This behavior is referenced from a HTML5 WG wiki entry on flow content: HTML5's restrictions on nesting of p elements and on what p elements may contain, are due to, quote: "peculiarities of the parser" that causes p to be auto-closed ..
这篇关于嵌套 <p>嵌套 <div> 时不起作用将要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!(或其他块级元素)将隐式关闭任何打开的
display:block;
的 不会关闭
作为
不是块级元素.
元素不能嵌套在 HTML5 中.文档中的关键短语是:短语内容的运行 [不包括
元素] 形成段落".此外,HTML5 试图在许多方面向后兼容,在 "对内容模型和属性值的限制":
<p>
like this:<p>The following:
<p>one</p>
<p>two</p>
</p>
<div>
instead. But today I used <p>
but it seems that both Emacs and Google Chrome both would consider the outer <p>
closed as soon as it see a new <p>
is started. (the DOCTYPE
is HTML 4.01 Strict).<p>
is no more than a <div>
but just with some pre-defined margin and padding, but is it true that <p>
cannot be nested? If so, what rule says that it cannot?<p>
(or other block-level element) will implicitly close any open <p>
.
<div>
would have implicitly closed the paragraph!<span>
with display:block;
would not have closed the <p>
as a <span>
is not a block-level element.
<p>
elements cannot nest in HTML5. The key phrase from the documentation is: "Runs of phrasing content [which does not include <p>
elements] form paragraphs". Furthermore, HTML5, trying to be backwards-compatible in many aspects, has a rationale on "Restrictions on content models and on attribute values":