Where can I find a list of proper HTML nesting standards?

我的梦境 提交于 2019-11-28 13:01:49

问题


I've been crawling Stack Overflow and the rest of the web, looking for proper nesting standards in regards to all HTML elements, but the search seems to be in vain.

Which is why I am asking, where is there a reference of the proper nesting standards (such as the fact that you can't put <div> tags inside a <p> tag)?


回答1:


Try the language definition

(hint: there are indexen of elements and attributes if you scroll down to the bottom)

EDIT: there's also the latest draft of HTML5




回答2:


In HTML5, each element has

  • a list of categories it belongs to, and
  • a content model.

The content model describes (with the help of categories) the expected contents of an element (e.g., which elements are allowed as children). See Elements → Content models for a list of the categories.

Example: The p element is defined as:

Categories:

  • Flow content.
  • Palpable content.

Content model:

  • Phrasing content.

So p can contain any element that belongs to the "phrasing content" category (a, abbr, …).

And p can be child of any element whose content model expects "flow content" and/or "palpable content". (For convenience, "contexts in which this element can be used" describes those elements (but it’s non-normative).)


Note that other specifications may modify the definitions. For example, RDFa and Microdata extend HTML5 to allow meta/link in the body.



来源:https://stackoverflow.com/questions/21345918/where-can-i-find-a-list-of-proper-html-nesting-standards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!