CSS Selector Brother Selector (~ and +)

Source: Internet
Author: User

Today in the old people to write the style of the Web page, encountered this selector, ' ~ ', at that time I was ignorant force, silly confused ' + ' with ' ~ ' difference, although I know they are brothers selector.

Later on-line search, perhaps I find the wrong way, did not find the answer I want, so privately take these two selectors to test a bit. It turns out this is the case.

First come to the code to speak:

(1), ' ~ ' Selector

<! DOCTYPE html>

The effect is as follows:

        

(2), ' + ' selector

  

<! DOCTYPE html>

Code or those, just the ' ~ ' replaced with ' + ', the result is very different.

      

With these two examples, it can be found that although these two selectors all represent sibling selectors, the ' + ' selector represents a sibling element that is adjacent to an element, that is, next to each other. The ' ~ ' selector represents the specified element of all siblings after an element, emphasizing all.

CSS Selector Brother Selector (~ and +)

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.