JQuery: CSS selector parity match nth-child (even) _ jquery
Source: Internet
Author: User
Today, I learned about jQuery and saw the nth-child (even) usage. I specifically found the usage of this selector. In the CSS3 standard, the usage is very powerful. In this regard, I will give a general introduction to the usage of nth-child () in CSS3:
CSS3 pseudo-class selector: nth-child ()
Briefly summarize several nth-child () usage.
First, nth-child (number) directly matches the number element. The number must be an integer greater than 0.
(EG) li: nth-child (3) {background: orange;}/* set the 3rd LI backgrounds to orange */
Second, nth-child (an) matches all elements whose multiples are. The letter n in the parameter "an" cannot be the default value. It is a symbol of the method of writing multiples, such as 3n and 5n.
(EG) li: nth-child (3n) {background: orange;}/* put 3rd, 6th, 9th ,... Set the background of LI in multiples of all 3 to orange */
Third, nth-child (an + B) and nth-child (an-B) group elements first. Each group has a, and B is the sequence number of the members in the group, the letter n and the plus sign + cannot be default, and the position cannot be changed. This is a sign of this writing, where a and B are positive integers or 0. Such as 3n + 1 and 5n + 1. But the plus sign can be changed to a minus sign, which matches the-B number in the group. (In fact, an can also be a negative number, but it is left for the next part .)
(EG) li: nth-child (3n + 1) {background: orange;}/* match 1st, 4th, 7th ,... , Each 3 is a group of 1st LI */
Li: nth-child (3n + 5) {background: orange;}/* match 5th, 8th, 11th ,... , Starting from 5th, each 3 is a group of 1st LI */
Li: nth-child (5n-1) {background: orange;}/* match 5th-1 = 4, 10th-1 = 9 ,... , A multiple of 5th minus 1 LI */
Li: nth-child (3n ± 0) {background: orange;}/* equivalent to (3n )*/
Li: nth-child (± 0n + 3) {background: orange;}/* equivalent to (3 )*/
Fourth: nth-child (-an + B) Here is a negative Positive, cannot be default, otherwise meaningless. In this case, it is similar to nth-child (an + 1). It matches 1st, but the difference is that it calculates backwards, starting from the second, therefore, it cannot match more than B.
(EG) li: nth-child (-3n + 8) {background: orange;}/* match 8th, 5th, and 2nd LI */
Li: nth-child (-1n + 8) {background: orange;}/* or (-n + 8), matching the first 8 (including 8th) LI, this is a more practical point. It is used to limit the first N matches */
Fifth, nth-child (odd) and: nth-child (even) match the elements with odd numbers and even numbers respectively. The odd (odd) and (2n + 1) results are the same; The even (even) and (2n + 0) and (2n) results are the same.
This method can be used in jQuery to achieve the stripe effect:
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.