Изменения

Перейти к: навигация, поиск

HTML Nesting

7107 байтов добавлено, 19:09, 9 февраля 2011
м
Новая страница: «== Legend == * An uppercase word stands for the corresponding element. (Note that by [http://www.w3.org/TR/xhtml1/ XHTML] rules, element names must be written in lo...»
== Legend ==

* An uppercase word stands for the corresponding element. (Note that by [http://www.w3.org/TR/xhtml1/ XHTML] rules, element names must be written in lower case, e.g. <code>&lt;html></code>, not <code>&lt;HTML></code>.)
* A lowercase word is a term which describes a collection of HTML elements.
* Each entry is followed by a list of elements which may appear within the elements specified by the entry. If there is no such list, no nested elements are allowed. This means that only text (#PCDATA, see next item) is allowed inside the element; but if the note ''(empty)'' is given, it means that no content whatsoever is allowed. However, for '''flow''', '''inline''', '''block''', '''OBJECT''', and '''BODY''' the allowed contents are described separately under the main entries for them.
* [http://www.webreference.com/dlab/books/html/3-5.html#3-5-2-2 #PCDATA] means «parsed character data», which is plain text (without HTML tags, but «[http://www.cs.tut.fi/%7Ejkorpela/HTML3.2/3.10.html#esc escape sequences]» such as <code>&amp;auml;</code> and <code>&amp;#228;</code> are allowed)
* [http://www.w3.org/TR/html4/types.html#type-cdata CDATA] means «character data», which is plain text where even «escape sequences» aren’t interpreted; for a much better explanation, see the article ''[http://www.flightlab.com/%7Ejoe/sgml/cdata.html CDATA Confusion]'' by [http://www.flightlab.com/%7Ejoe/ Joe English]
* ''excluding'' … means that the element must not contain any of the listed elements, directly or indirectly.

----

The information here is based on the DTDs, basically the [http://www.w3.org/TR/1999/REC-html401-19991224/sgml/dtd.html Strict DTD], in the [http://www.w3.org/TR/1999/REC-html401-19991224/ 1999-12-24 version] of the ''[http://www.w3.org/TR/html401 HTML 4.01 Specification]''.

Note that [http://www.w3.org/TR/xhtml1/ XHTML 1.0] is, as its subtitle says, «A Reformulation of HTML 4 in XML 1.0», so the nesting rules are the same as in HTML 4.01. However, there are the following differences that affect the nesting rules:
* The content of <code>script</code> and <code>style</code> elements is CDATA in HTML 4 but #PCDATA in XHTML.
* In XHTML, a <code>table</code> element may have a <code>tr</code> element as its direct constituent. In HTML 4.01, that’s not allowed, but note that since the start and end tags of a <code>tbody</code> element are omissible in HTML 4.01, this is not a big difference. However, note that when a <code>table</code> element directly contains a <code>tr</code> element, an intervening <code>tbody</code> element is implied by HTML 4.01 rules but not by XHTML rules, and this matters e.g. when you have a style sheet which uses <code>tbody</code> as a selector.

Moreover, some of the restrictions on nesting are ''expressed'' differently; due to metalanguage differences, some limitations are described in prose only in the XHTML specification, and this implies that a [http://www.htmlhelp.com/faq/html/all.html#error-check validator] will not catch such violations of the limitations when validating against XHTML DOCTYPE but will catch them when an HTML DOCTYPE is used. See section ''[http://www.w3.org/TR/xhtml1/#diffs Differences with HTML 4]'' in the ''XHTML 1.0 Specification''.

== Nesting rules for HTML 4.01 Transitional ==

HTML
* HEAD
** TITLE ''(required)''
** SCRIPT, STYLE
*** '''CDATA'''
** ISINDEX, BASE, META, LINK ''(empty)''
** [[#object|OBJECT]] ''(see content model below)''
* BODY
** INS, DEL ''([http://www.w3.org/TR/REC-html40/struct/text.html#edef-del special rules] apply)''
*** '''flow'''
** '''flow'''
*** '''block'''
**** P, H1, H2, H3, H4, H5, H6
***** '''inline'''
**** UL, OL
***** LI
****** '''flow'''
**** DIR, MENU
***** LI
****** '''inline''' ''exluding block''
**** DL
***** DT
****** '''inline'''
***** DD
****** '''flow'''
**** PRE
***** '''inline''' ''excluding IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT''
**** DIV, CENTER, BLOCKQUOTE, IFRAME
***** '''flow'''
**** NOSCRIPT
***** '''flow'''
**** NOFRAMES
***** '''flow'''
**** FORM
***** '''flow''' ''excluding an enclosed FORM''
**** ISINDEX, HR ''(empty)''
**** TABLE
***** CAPTION
****** '''inline'''
***** COLGROUP
****** COL ''(empty)''
***** COL ''(empty)''
***** THEAD, TBODY, TBODY
****** TR
******* TH, TD
******** '''flow'''
**** ADDRESS
***** '''inline'''
***** P
****** '''inline'''
**** FIELDSET
***** '''#PCDATA'''
***** '''flow'''
***** LEGEND
****** '''inline'''
*** '''inline'''
**** '''#PCDATA'''
**** TT, I, B, U, S, STRIKE, BIG, SMALL, FONT, EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, SUB, SUP, Q, SPAN, BDO
***** '''inline'''
**** A
***** '''inline''' ''excluding an enclosed A element''
**** OBJECT, APPLET
***** PARAM ''(empty)''
***** '''flow'''
**** IMG, BASEFONT, BR ''(empty)''
**** SCRIPT
***** '''CDATA'''
**** MAP
***** AREA ''(empty)''
***** '''block'''
**** INPUT ''(empty)''
**** SELECT
***** OPTGROUP
****** OPTION
***** OPTION
**** TEXTAREA
**** LABEL
***** LABEL ''excluding enclosed LABEL''
**** BUTTON
***** '''flow''' ''excluding A, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, FORM, ISINDEX, FIELDSET, IFRAME''

== Allowed nesting of elements in HTML 4 Strict (and XHTML 1.0 Strict) ==

HTML

* HEAD
** TITLE ''(required)''
** SCRIPT, STYLE
*** CDATA
** BASE, META, LINK ''(empty)''
** [http://www.cs.tut.fi/%7Ejkorpela/html/strict.html#object OBJECT] ''(see content model below)''
* BODY
** INS, DEL ''([http://www.w3.org/TR/REC-html40/struct/text.html#edef-del special rules] apply)''
*** '''flow'''
**** '''block'''
**** '''inline'''
** SCRIPT
*** '''CDATA'''
** '''block'''
*** P, H1, H2, H3, H4, H5, H6
**** '''inline'''
***** '''#PCDATA'''
***** TT, I, B, BIG, SMALL, EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, SUB, SUP, Q, SPAN, BDO
****** '''inline'''
***** A
****** '''inline''' ''excluding an enclosed A element''
***** OBJECT
****** PARAM ''(empty)''
****** '''flow'''
***** IMG, BR ''(empty)''
***** SCRIPT
****** CDATA
***** MAP
****** AREA ''(empty)''
****** '''block'''
***** INPUT ''(empty)''
***** SELECT
****** OPTGROUP
******* OPTION
****** OPTION
***** TEXTAREA
***** LABEL
****** LABEL ''excluding enclosed LABEL''
***** BUTTON
****** '''flow''' ''excluding A, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, FORM, FIELDSET''
*** UL, OL
**** LI
***** '''flow'''
*** DL
**** DT
***** '''inline'''
**** DD
***** '''flow'''
*** PRE
**** '''inline''' ''excluding IMG, OBJECT, BIG, SMALL, SUB, SUP''
*** DIV
**** '''flow'''
*** BLOCKQUOTE
**** '''block'''
**** SCRIPT
***** '''CDATA'''
*** NOSCRIPT
**** '''flow'''
*** FORM
**** '''block''' ''excluding an enclosed FORM''
**** SCRIPT
***** CDATA
*** HR ''(empty)''
*** TABLE
**** CAPTION
***** '''inline'''
**** COLGROUP
***** COL ''(empty)''
**** COL ''(empty)''
**** THEAD, TBODY, TBODY
***** TR
****** TH, TD
******* '''flow'''
*** ADDRESS
**** '''inline'''
*** FIELDSET
**** '''#PCDATA'''
**** '''inline'''
**** '''flow'''
**** LEGEND
***** '''inline'''

== Links ==

* http://hi.baidu.com/tatbaby/blog/item/722e088b762fde18c8fc7aed.html
* http://www.cs.tut.fi/~jkorpela/html/nesting.html

Навигация