Nesting block level elements inside the

tag… right or wrong?

前端 未结 6 2231
遇见更好的自我
遇见更好的自我 2020-11-22 10:13

Is it syntactically and semantically correct to nest

or any other block level element inside the

tag. I am talking about HTML

6条回答
  •  鱼传尺愫
    2020-11-22 10:49

    Syntactically, a div inside a p is invalid in all standards of HTML. Moreover, when using a conforming HTML parser, it is impossible to place a

    element inside a

    in the DOM because the opening

    tag will automatically close the

    element.

    Semantically, the correct choice depends on the content that you are marking up. You will need to show at least a sample full paragraph and possibly the content surrounding it to be sure of providing sufficient information for the correct semantic mark-up to be determined.

    However, given that both

    and are semantics free, and that CSS in no way can ever change that, if you are certain that the contents of the

    tag truly form a paragraph, and that gets you the presentational effect that you are seeking, then that is valid HTML and would be a wholly appropriate solution.

提交回复
热议问题