序号选择器
摘抄
原文链接:https://blog.csdn.net/weixin_39676449/article/details/88726425
css中,对同等级,第n个元素的相关操作。
一.不区分类型:
- :first-child
选中同级别中第一个标签 - :last-child
选中同级别中最后一个标签 - :nth-last-child(n)
选中同级别中倒数第n个标签 - :nth-child(n)
选中同级别中第n个标签 - :only-child
选中同级别中唯一子元素标签
二.区分类型:
:first-of-type
选中同级别中同类型第一个标签:last-of-type
选中同级别中同类型最后一个标签:nth-of-type
选中同级别中同类型第n个标签:nth-last-of-type
选中同级别中同类型倒数第n个标签:only-of-type
选中同级别中唯一同一类型子元素标签
三.奇偶选择:
:nth-child(odd)
选择级别中所有奇数:nth-child(even)
选择级别中所有偶数:nth-child(x+y)
x和y是用户自定义的,n为计数器,从0开始递增选择,到元素的总个数停止。