Usually in the code practice, often use the descendant selector, sub-selectors will also be used, here to do a summary:
1, descendants selector and child selector differ:
① does not have the same wording:
Descendant selectors are identified as: spaces
such as: UL li{width:150px;} "between Ul and Li is separated by a space"
The child selector is identified as:>
such as: ul>li{width:150px;} "> separated between UL and Li"
The identity of the adjacent sibling selector is: +
such as: H1 + P {margin-top:50px;} [H1 and P separated by + ]
The ② function is not the same:
Descendant selectors (descendant selector), also known as containing selectors, can select elements of an element's descendants (descendant elements), as in the example above, the descendant selector is all the LI elements in all the elements surrounded by the selection of UL, including the son element, the grandson element, Great-grandchild elements and so on.
In contrast to descendant selectors, child selectors can only select elements that are elements of the son element of an element, and the sub-selector selects only the LI element in the son element that surrounds the UL, not including the grandchild element, the great-grandchild element, and so on.
The adjacent sibling selector is well understood, which is to select the element immediately after the other element, and both have the same parent element.
③ compatibility is not the same:
The descendant selector is compatible with mainstream browsers.
The child selector and the adjacent sibling selector in IE6 are unsupported selectors and will be out bug!
2, descendant selector, child selector and adjacent sibling selector combined with examples:
Take a look at the selector below:
HTML > Body table + ul {margin-top:20px;}
This selector is interpreted as: Select the first adjacent sibling UL element that appears immediately after the table element, which is contained within a BODY element, and the body element itself is a child of the HTML element.
CSS descendant selectors, sub-selectors and neighboring sibling selectors