CSS Neighbor Sibling Selector

Source: Internet
Author: User

Neighbor Sibling Selector definition: Select the element immediately after the other element , and both have the same parent element.

  

Code One:
<body> + p{ color:red; }

Effect:

Only the first P element is selected here, because only the first P element and the H1 relationship are immediately adjacent to the sibling, and the p after the first P element is not immediately followed by the H1.

      
   Code two:
<Body> <Li>111</Li> <Li>111</Li> <Li>111</Li> </ul> <ol> <Li>111</Li> <Li>111</Li> <Li>111</Li> </ol> </Body>Use selector Li + li {color:red; }

Effect:

  

Why does each Li apply a style?

Since the second Li, each of the two Li directly between each of the Li + li is formed immediately after the relationship, so are selected

CSS Neighbor Sibling Selector

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.