Reference:
HTML tag nesting rules - MOOC
HTML tag nesting rules - Blog Park
WEB standard series - HTML element nesting
block elements:
address, blockquote, center, dir, div, dl, dt, dd, fieldset, form, h1 ~h6, hr, isindex, menu, noframes, noscript, ol, p, pre, table, ul, etc.
Inline elements:
a, abbr, acronym ,b,bdo,big,br,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea , tt, u, var, etc.
Nesting rules:
Blocks can contain blocks and inlines, and inlines can only contain inlines Block elements can contain inline elements or certain block elements, but inline elements cannot contain block elements. They can only contain other inline elements Titles and paragraphs cannot contain blocks There are several special block-level elements that can only contain inline elements and cannot contain block-level elements. These special tags are h1, h2, h3, h4, h5, h6 , p, dt Blocks and inline cannot be juxtaposed Block-level elements are juxtaposed with block-level elements, and inline elements are juxtaposed with inline elements Note:
li is a block-level element and can nest block-level elements (including ul).
Some tags have fixed nesting rules, such as ul contains li, ol contains li, dl contains dt and dd, etc.
Let me explain here, although you can use display to set block and inline, it is obviously not rigorous to define the nesting relationship. (I wonder if search engines will crawl CSS content?)
Advanced knowledge
WEB Standard Series-HTML Element Nesting
Since I don’t have access to HTML5 now, I will keep
Problems that may be caused by nesting errors
Element start and end tag embedding set of errors, the page can be parsed normally in most browsers, but IE9 will have parsing errors Embedding elements such as within the
element will cause parsing errors in all browsers
Embedding and other elements within
~ elements can be parsed by all browsers normally
Embedding elements within elements will cause all browsers to Parsing error of the browser (a cannot nest interactive elements such as buttons and inputs) Inserting non-list sibling elements into list elements such as will cause parsing errors in IE6IE7 Actually, it is not very reasonable to say parsing errors here. It should mean that the results parsed by the browser are inconsistent with the results we expect, but Any nested errors will not cause significant differences in page rendering. Big mistake.
Finally:
Although we can nest tags, in order To improve browser rendering efficiency, we should minimize nested tags and flatten them. < li > " >< div > div > a > h4 > li >
ul >
The above code comes from Facebook, and I instantly felt so awesome! Ha ha.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31