CSS3 New Selector Overview

Source: Internet
Author: User
Selector:first-child This is the descendant selector. Weird, be careful to avoid rather than understand.

Selector:first-child

The first element in the current selector selected element collection

Selector:last-child

The last element in the collection of currently selector selected elements.

However, there is a problem: Last-child does not take effect.

Should be:
1 parent element of current Selector
2 Parent all child elements, [a,b,c]
3 The first element of a collection of child elements, if it is selector
4 set the style to take effect.

  **if (selecor.parent.childElementList.firstElement = = = Selector) {     effective  }**

So use these two pseudo-classes to add a parent element on it. It can be thought of as the first realization.

Nth-child () also applies to the above rules.
Note that n here has a lot of room for development, you can achieve odd/even, choose which few, from which to choose.

Nth-last-child () reverse the selection
: First-of-type
: Last-of-type
: Nth-of-type
: Nth-last-of-type
: Root
Select the document root element. It's HTML.
: Empty
Select an element that has no spaces in the element
: not
Negative Selector

: Only-child
It only takes effect when the collection has only one element.

:: Selection
Only two properties can be set: Background,color.


Selector:first-child This is the descendant selector. Weird, be careful to avoid rather than understand.

Selector:first-child

The first element in the current selector selected element collection

Selector:last-child

The last element in the collection of currently selector selected elements.

However, there is a problem: Last-child does not take effect.

Should be:
1 parent element of current Selector
2 Parent all child elements, [a,b,c]
3 The first element of a collection of child elements, if it is selector
4 set the style to take effect.

  **if (selecor.parent.childElementList.firstElement = = = Selector) {     effective  }**

So use these two pseudo-classes to add a parent element on it. It can be thought of as the first realization.

Nth-child () also applies to the above rules.
Note that n here has a lot of room for development, you can achieve odd/even, choose which few, from which to choose.

Nth-last-child () reverse the selection
: First-of-type
: Last-of-type
: Nth-of-type
: Nth-last-of-type
: Root
Select the document root element. It's HTML.
: Empty
Select an element that has no spaces in the element
: not
Negative Selector

: Only-child
It only takes effect when the collection has only one element.

:: Selection
Only two properties can be set: Background,color.

Related Article

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.