p 的内容必须是 flow content (
https://html.spec.whatwg.org/#flow-content而 div 是 Palpable content (
https://html.spec.whatwg.org/#palpable-content所以 p 里面不能放 div,
至于为什么 div 会被吐出来,就是因为根据
https://html.spec.whatwg.org/#concept-element-tag-omission 规则,元素结束标签在一些情况可以省略,而多余的结束标签会被忽略
p 的结束标签可以省略
https://html.spec.whatwg.org/#the-p-elementTag omission in text/html:
A p element's end tag can be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.