Is it wrong to change a block element to inline with CSS if it contains another block element?

后端 未结 9 1337
遇见更好的自我
遇见更好的自我 2020-11-22 16:25

I know it\'s wrong to put a block element inside an inline element, but what about the following?

Imagine this valid markup:

This

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 17:14

    Regardless if it's valid or not, the element structure is wrong. The reason that you don't put block elements inside inline elements is so that the browser can render the elements in an easily predictable way.

    Even if it doesn't break any rules for either HTML or CSS, still it creates elements that can't be rendered as intended. The browser has to handle the elements just as if the HTML code was invalid.

提交回复
热议问题