Introduction and examples of CSS3 descendant selectors and sibling selectors

Source: Internet
Author: User

The CSS Selector Level 3 specification defines some connection selectors (or combination selectors) related to the document hierarchy.

Divided into descendant selectors (descendant Combinator/child combinators) and sibling selectors (Sibling combinators):


The descendant selectors are divided into the following 3:

1. Spaces. Div p: Indicates that P is the descendant element of the Div, and the div is the ancestor of P. The selector selects the P descendant elements under all Div.

2. Arrows (>). Represents a direct relationship. div > P represent the elements of the div's son generation.

3. asterisk (*). Represents an alternate generation relationship. DIV * P represents the grandson and the following elements of the Div.

Online Example: http://wow.techbrood.com/fiddle/15759


The sibling selector can be divided into the following 2:

1. plus sign (+). Represents a relationship that follows. H1 + H2: Represents the H2 element immediately following the H1.
2. Wave number (~). Represents a successor relationship. H1 ~ H2: Represents a subsequent H2 element that is under the same parent element as the H1 element (the middle can be separated by other elements).

Online Example: http://wow.techbrood.com/fiddle/15761


About the CSS3 selector reference read:

Http://techbrood.com/Guide/h5b2a?p=css-selectors

Http://techbrood.com/Guide/h5b2a?p=css-pseudo-classes


by Iefreer

Introduction and examples of CSS3 descendant selectors and sibling 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.