css 伪类选择器 结构伪类

css 伪类选择器 结构伪类

常用的:

:first-child 所有兄弟元素中的第一个
:last-child 所有兄弟元素中的最后一个
:nth-child(n) 所有兄弟元素中的第n个
:first-of-type 所有同类型兄弟元素中的第一个
:last-of-type 所有同类型兄弟元素中的最后一个
:nth-of-type(n) 所有同类型兄弟元素中的第n个

关于n的值:

  1. 0或不写:什么都不选中
  2. 2n或even:选中序号为偶数的子元素
  3. 2n+1或odd:选中序号为奇数的子元素
  4. -n+3: 选中的是前3个

:nth-last-child(n) 所有兄弟元素中的倒数第n个
:nth-last-of-type(n) 所有同类型兄弟元素中的倒数第n个
:only-child 选择没有兄弟的元素(独生子女)
:only-of-type 选择没有同类型兄弟的元素
:root 根元素
:empty 内容为空元素(空格也算内容)

猜你喜欢

转载自blog.csdn.net/m0_48546501/article/details/130764148