JQuery by the way learn the next CSS selector parity matching nth-child (even) _jquery
Source: Internet
Author: User
In this respect, I put the CSS3 standard Nth-child () the use of the general introduction:
CSS3 Pseudo class selector: Nth-child ()
A simple summary of several uses of Nth-child ().
First: Nth-child (number) directly matches the first number element. The argument number must be an integer greater than 0.
(EG) Li:nth-child (3) {Background:orange} /* Set the background of the 3rd Li to Orange * *
The second: Nth-child (an) matches all elements that are multiples a. Where the letter N in the parameter an is not default, it is a sign of multiple notation, such as 3n, 5n.
(EG) Li:nth-child (3n) {Background:orange} /* Set the background of Li for the 3rd, 6th, 9th 、...、 multiples of 3 to orange/
Third: Nth-child (an+b) and: Nth-child (an-b) First group elements, each group has a, B is the number of members in the group, where the letter N and plus + can not be default, location is not interchangeable, this is the symbol of the wording, where the a,b are positive integers or 0. such as 3n+1, 5n+1. However, the plus sign can change to a minus sign, at which point A-b in the Match Group. (In fact, a front can also be a minus, but left to the next part of the story.) )
(EG) Li:nth-child (3n+1) {background:orange;} /* Match 1th li*/of the 1th, 4th, 7th 、...、 for each group of 3
Li:nth-child (3n+5) {background:orange;} /* Match the 5th, 8th, 11th 、...、 the 1th li*/from the beginning of 5th to a group of 3
Li:nth-child (5n-1) {background:orange;} /* matches the multiples of 5-1=4, 10-1=9 、...、 5th, minus 1 li*/
Li:nth-child (3n±0) {background:orange;} /* equivalent to (3n) * *
Li:nth-child (±0n+3) {background:orange;} /* equivalent to (3) * *
Four: Nth-child (-an+b) Here a negative one positive, can not be default, otherwise meaningless. This is similar to the following: Nth-child (an+1) is the 1th match, but the difference is that it is inverted, from the beginning of the second back, so it will match up to no more than B.
(EG) Li:nth-child ( -3n+8) {background:orange;} /* matches 8th, 5th, and 2nd li*/
Li:nth-child ( -1n+8) {background:orange;} /* OR (-n+8), matching the first 8 (including the 8th) LI, this is a more practical point, used to limit the first n matches often used * *
V: nth-child (Odd) and: Nth-child (even) match the elements with odd and even numbers, respectively. The odd number (odd) is the same as the (2n+1) result, even (even) and (2n+0) and (2n) results.
This method is used in jquery to achieve stripe effects:
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.