段落标签未关闭? [英] paragraph tag not closed?

查看:245
本文介绍了段落标签未关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将html代码简化为此

I simplified my html code down to this

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

但是,当我运行它并打开页面源代码时,它说作用域中没有p元素,但是看到了p end标签".它运行良好,但出于某些奇怪的原因,Intellij Idea和Firefox都将其显示为不必要的/p标记.我的电脑故障了吗?

However, when I run it and open up the page source, it says "No p element in scope but a p end tag seen". It runs fine but for some strange reason, Intellij Idea and Firefox both show it as an unnecessary /p tag. Is my computer glitching out?

Chrome认为还可以

Chrome says it's ok

推荐答案

有一组固定的元素,属于

There's a fixed set of elements, belonging to Phrasing content category, that can be children of <p> element:

短语内容是文档的文本以及 在段落内标记该文本.分阶段运行 内容形式的段落.

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>元素也不属于此处.在这种情况下,<p>元素会自动关闭.引用文档:

<h2> element, as many other block-level ones, doesn't belong here. In this case, <p> element closes automatically. Quoting the docs:

如果p元素紧随其后,则可以省略p元素的结束标签 后跟addressarticleasideblockquotedivdlfieldsetfooterformh1h2h3h4h5h6headerhgrouphrmainolppresectiontableul元素,或者如果没有更多元素 父元素中的内容,且父元素不是 元素.

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的结构如下:

In this particular case, the structure of DOM is as follows:

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

...,而且,正如您所看到的,结束标记不是很受欢迎.实际上,您应该感谢Firefox DOM Inspector标记此错误. )

... and, as you can see, the end tag isn't really welcome. Actually, you should be grateful for Firefox DOM Inspector marking this error. )

这篇关于段落标签未关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆