简体   繁体   English

范围内没有p元素,但看到了p结束标记.w3c验证

[英]No p element in scope but a p end tag seen.w3c validation

My HTML is as as below. 我的HTML如下所示。 I have opened all elements and closed them. 我已打开所有元素并关闭它们。 Still when I check it on w3c it shows error. 还是当我在w3c上检查它时它显示错误。 I cant figure it out. 我弄清楚了。

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Untitled Document</title>
    </head>

    <body>
        <p>
            <div class="inr_content clearfix">
                 <div class="col2 first fl">
                      to provide a drive-in services.
                 </div>
                 <div class="col2 last fr">
                      to provide a drive-in services.
                 </div>
            </div>
        </p>
    </body>
</html>

That's because you are nesting a block level element inside the p tag which is invalid. 那是因为你在p标签内嵌套了一个无效的块级元素。 You can only nest inline elements such as span , a and img inside p tag. 您只能在p标记内嵌入内联元素,例如spanaimg So your markup is invalid, consider making something like 所以你的标记是无效的,考虑做类似的事情

<div class="inr_content clearfix">
   <div class="col2 first fl">
      <p>to provide a drive-in services.</p>
   </div>
   <div class="col2 last fr">
      <p>to provide a drive-in services.</p>
   </div>
</div>

From W3C [1] : 来自W3C [1]

The P element represents a paragraph. P元素代表一个段落。 It cannot contain block-level elements (including P itself). 它不能包含块级元素(包括P本身)。

1 - Reference 1 - 参考

Since the syntax of the p element does not allow a div child, and the end tag </p> may be omitted, the validator (and a browser) implies </p> when it encounters a <div> tag when parsing a p element. 由于p元素的语法不允许div子句,并且可能省略结束标记</p> ,因此验证程序(和浏览器)在解析p时遇到<div>标记时隐含</p>元件。 That is, when p is being parsed (or “is open”), the start tag of a div element implicitly closes it, as if the markup had: 也就是说,当正在解析p (或“打开”)时, div元素的开始标记会隐式关闭它,就好像标记具有:

<body>
    <p>
        </p><div class="inr_content clearfix">
             <div class="col2 first fl">

This means that there is a p element with only whitespace in it. 这意味着有一个p元素只有空格。 The </p> tag that appears later thus has no matching start tag, and it is reported as invalid. 之后出现的</p>标记没有匹配的开始标记,并且报告为无效。 Browsers ignore such homeless end tags, but validators have to report them. 浏览器会忽略此类无家可归的结束标记,但验证者必须报告它们。

The minimal change is to remove the </p> tag. 最小的变化是删除</p>标记。 Whether this is adequate depends on what you want. 这是否足够取决于你想要什么。 Removing the <p> tag as well would remove the p element, and this would affect rendering. 删除<p>标签也会删除p元素,这会影响渲染。 Even though the p element has no content rendered (content height is 0), it has default top and bottom margin, possible creating some empty vertical space. 即使p元素没有渲染内容(内容高度为0),它也有默认的上下边距,可能会创建一些空的垂直空间。

If you do not want such space, just remove the <p> tag (along with </p> of course). 如果您不想要这样的空间,只需删除<p>标签(当然还有</p> )。 If you do want some space, it is usually still best to remove the tag, but then you would additionally set, in CSS, some suitable margin-top value on the top-level div element. 如果你确实需要一些空间,通常最好删除标签,但是你还可以在CSS中在顶级div元素上设置一些合适的margin-top值。

Even though p elements containing only whitespace are allowed in HTML5, they are not recommended. 即使HTML5中允许仅包含空格的p元素,也不建议使用它们。 This is part of the general recommendation related to so-called palpable content : “elements whose content model allows any flow content or phrasing content should have at least one node in its contents that is palpable content”. 这是与所谓的可触知内容相关的一般建议的一部分:“内容模型允许任何流内容或措辞内容的元素应在其内容中至少有一个节点是可触知的内容”。 And text is usually palpable content, but not if it consists of whitespace only. 文本通常是可触及的内容,但如果它只包含空格,则不会。

您不能在语义上将div放在<p>标记内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用时 <p class=xxx> 我在W3C合规性检查器上收到响应“范围内没有p元素,但看到ap结束标签。” - When using <p class=xxx> I am getting the response “No p element in scope but a p end tag seen.” on W3C compliance checker 没有 P 元素,但看到了一个结束标签 - No P element but an end tag seen 验证:元素“P”的结束标记未打开 - Validation: end tag for element “P” which is not open W3C HTML验证错误:“流浪结束标记 </head> ”和“开始标签 <body> 看到了,但是相同类型的元素已经打开了” - W3C HTML validation errors: “Stray end tag </head>” and “Start tag <body> seen but an element of the same type was already open” 从p标签获取元素 - getting the element from the p tag <p></p>在div中标记 - <p> </p> tag in div W3C验证程序:“看到一个开始标记,但是相同类型的元素已经打开。” - W3C validator: “Start tag a seen but an element of the same type was already open.” W3C HTML5 错误开始标签头看到但相同类型的元素已经打开 - W3C HTML5 ERROR Start tag head seen but an element of the same type was already open 带有样式元素的 html p 标签的正则表达式 - regexp for html p tag with style element 杂散开始标签td &amp;&amp;杂散结束标签td。 w3c验证 - Stray start tag td && Stray end tag td. w3c validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM