序号选择器

摘抄

原文链接:https://blog.csdn.net/weixin_39676449/article/details/88726425

css中,对同等级,第n个元素的相关操作。

一.不区分类型:

  1. :first-child
    选中同级别中第一个标签
  2. :last-child
    选中同级别中最后一个标签
  3. :nth-last-child(n)
    选中同级别中倒数第n个标签
  4. :nth-child(n)
    选中同级别中第n个标签
  5. :only-child
    选中同级别中唯一子元素标签

二.区分类型:

  1. :first-of-type
    选中同级别中同类型第一个标签

  2. :last-of-type
    选中同级别中同类型最后一个标签

  3. :nth-of-type
    选中同级别中同类型第n个标签

  4. :nth-last-of-type
    选中同级别中同类型倒数第n个标签

  5. :only-of-type
    选中同级别中唯一同一类型子元素标签

三.奇偶选择:

  1. :nth-child(odd)
    选择级别中所有奇数

  2. :nth-child(even)
    选择级别中所有偶数

  3. :nth-child(x+y)
    x和y是用户自定义的,n为计数器,从0开始递增选择,到元素的总个数停止。