[英]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
标记内嵌入内联元素,例如span
, a
和img
。 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本身)。
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.