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

后端 未结 3 1191
南方客
南方客 2021-01-31 02:11

My HTML is as as below. I have opened all elements and closed them. Still when I check it on w3c it shows error. I cant figure it out.



        
3条回答
  •  半阙折子戏
    2021-01-31 02:53

    Since the syntax of the p element does not allow a div child, and the end tag

    may be omitted, the validator (and a browser) implies

    when it encounters a
    tag when parsing a p element. 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:

    
        

    This means that there is a p element with only whitespace in it. The

    tag that appears later thus has no matching start tag, and it is reported as invalid. Browsers ignore such homeless end tags, but validators have to report them.

    The minimal change is to remove the

    tag. Whether this is adequate depends on what you want. Removing the

    tag as well would remove the p element, and this would affect rendering. 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.

    If you do not want such space, just remove the

    tag (along with

    of course). 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.

    Even though p elements containing only whitespace are allowed in HTML5, they are not recommended. 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.

提交回复
热议问题