gpt4 book ai didi

html - 段落标签没有关闭?

转载 作者:行者123 更新时间:2023-12-04 22:57:20 25 4
gpt4 key购买 nike

我将我的 html 代码简化为这样

<!doctype html>
<body>
<div class="index-div">
<p id="whoarewe">
<h2>Who are we?</h2>
wersfgse
</p>
</div>
</body>
</html>

但是,当我运行它并打开页面源代码时,它显示“范围内没有 p 元素,但看到了 p 结束标记”。它运行良好,但由于某些奇怪的原因,Intellij Idea 和 Firefox 都将其显示为不必要的/p 标记。我的电脑出故障了吗?

编辑:Chrome 表示没问题 see look

最佳答案

有一组固定的元素,属于Phrasing content类别,可以是 <p> 的子项元素:

Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.

a abbr area (if it is a descendant of a map element) audio b bdi bdo br button 
canvas cite code data datalist del dfn em embed i iframe img input ins
kbd keygen label map mark math meter noscript object output
progress q ruby s samp script select small span strong sub sup svg
template textarea time u var video wbr Text

<h2>与许多其他 block 级元素一样,元素不属于这里。在这种情况下,<p>元素自动关闭。引用 the docs :

A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, div, dl, fieldset, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, 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 not an a element.

在这种特殊情况下,DOM 的结构如下:

<p id="whoarewe"></p>
<h2>Who are we?</h2>
wersfgse
</p>

...而且,如您所见,结束标记并不受欢迎。实际上,您应该感谢 Firefox DOM Inspector 标记了这个错误。 )

关于html - 段落标签没有关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32103397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com