CSS descendant selectors and Sub-selectors

Source: Internet
Author: User

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 ② function is not the same:
Descendant selectors (descendant selector), also known as containing selectors, can select elements of an Element's descendants , as in the previous example, the descendant selector is all the LI elements in all elements surrounded by a selection of ul, including son elements, grandson elements, 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.

③ compatibility is not the same:
The descendant selector is compatible with mainstream Browsers.
Sub-selectors in IE6 are not supported selectors, will be out bug!
2, descendant selector and childexamples of using selectors in Combination:

Take a look at the selector below:

Table.company td > P

The selector above selects all the P elements as child elements of the TD element, and the TD element itself is inherited from a TABLE element that class= "company".

CSS descendant selectors and Sub-selectors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.