[HTML5 + CSS3]CSS3 main Selector

Source: Internet
Author: User

CSS3 Selector has brought us a lot of convenience, previously can only use JS or specific elements to increase the specific class implementation effect, the following with the example record/share the role of each CSS3 selector.

(1) adjacent element selector x + y

<!--CSS -<styletype= "Text/css">Div ul + P{background:#F00; }</style><!--label -<Div>    <ul>I am the UL</ul>    <P>I'm p.</P>    <ol>I am the OL</ol>    <P>I'm p.</P></Div>

Browser effects:

Summary: Only select the P tag followed by UL, the other P tags are not selected.

(2) child element selector x > Y

<!--CSS -<styletype= "Text/css">ul{background:#000;Color:#FFF;}DIV > UL{background:#F00;}</style><!--label -<Div>    <ul>        <Li>I'm Ulli .<ul>I am level two UL</ul>        </Li>    </ul></Div>

Browser effects:

Summary: In order to better explain the problem, I initially gave all UL defined the background black. The actual display effect is the first UL background red, because we covered the CSS style in the beginning of the black,> selector will only select the immediate child elements, not the next generation of children.

(3) sibling element selector x ~ Y

<!--CSS -<styletype= "Text/css">UL ~ ol{background:#F00;}</style><!--label -<Div>    <ul>I am the UL</ul>    <ol>I am the OL</ol>    <P>I'm p.</P>    <ul>        <Li>            <ol>I'm level two ol.</ol>        </Li>    </ul>    <ol>I'm still ol '</ol></Div>

Browser effects:

Summary: A total of 3 ol,2 for the same level of UL, the instance shows the sibling ol element background is red, visible ~ The role of the selector: Select only the sibling specified element.

Not finished with, waiting to be updated ...

[HTML5 + CSS3]CSS3 main 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.