1、nth-child()的用法:
(1)td:nth-child(n){background: red;}:选择表格中第n个td标签
(2)td:nth-child(2n){background: red;}:选择表格中第偶数个td标签,例如第2、第4、第6等等
(3)td:nth-child(2n-1){background: red;}:选择表格中第基数个td标签,例如第1、第3、第5等等
(4)td:nth-child(n+2){background: red;}:表示选中了表格中第2个开始到结束的td标签
(5)td:nth-child(-n+2){background: red;}:表示选中了表格中第1个到第2个的td标签,即小于2的td标签
2、first-child()的用法:用来匹配符合选择器中的一组标签的第一个标签
例如:
td:first-child(){background: red;}:表示选中表格中的第一个td标签
3、last-child()的用法:用来匹配符合选择器中的一组标签的最后一个标签
例如:
td:last-child(){background: red;}:表示选中表格中的最后一个td标签
4、not()的用法:用来匹配不符合一组选择器的元素
例如:
td:not(last-child()){background: red;}:表示选中表格中除了最后一个td标签之后的其他所有的td标签
还可以链式使用:
td:not(first-child()):not(last-child()){background: red;}:表示选中表格中除了第一个和最后一个td标签之后的其他所有的td标签