CSS选择器nth-child()、first-child()、last-child()、not()

1. Usage of nth-child():

(1) td:nth-child(n){background: red;}: select the nth td tag in the table

(2) td:nth-child(2n){background: red;}: Select the even-numbered td tag in the table, such as the 2nd, 4th, 6th, etc.

(3) td:nth-child(2n-1){background: red;}: Select the cardinality td tag in the table, such as the 1st, 3rd, 5th, etc.

(4) td:nth-child(n+2){background: red;}: Indicates that the second td tag from the beginning to the end of the table is selected

(5) td:nth-child(-n+2){background: red;}: Indicates that the td tag from the first to the second in the table is selected, that is, the td tag less than 2

2. Usage of first-child(): used to match the first label that matches a set of labels in the selector

For example:

td:first-child(){background: red;}: Indicates the first td tag in the selected table

3. The usage of last-child(): used to match the last label that matches a set of labels in the selector

For example:

td:last-child(){background: red;}: Indicates the last td tag in the selected table

4. The usage of not(): used to match elements that do not meet a set of selectors

For example:

td:not(last-child()){background: red;}: Indicates that all td tags in the selected table except the last td tag

It can also be used in chains:

td:not(first-child()):not(last-child()){background: red;}: Indicates that all other td tags in the selected table except the first and last td tags

Guess you like

Origin blog.csdn.net/m0_46318298/article/details/128407978