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

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标签

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值