css3 新增了一些伪类选择器的解析(保证记住)

css3 新增了一些伪类选择器

比如: selecor:first-child

不要费力去理解他们到底为了解决什么问题, 是对集合进行操作还是怎么怎么着, 记住这么一个规则:
如果 selector:first-child 生效, 需要:
    **selector.parent.children.first == selector;**

也就是: 当前元素的父元素的第一个子元素就是它本身, 此时, selector:first-child 才会生效.

同理:
selector:last-child, 需要:

selector.parent.children.last == selector;  才会生效

第二类

nth-child()
注意这里的 n 有很大发展空间, 可以实现 奇/偶, 选择哪几个, 从哪几个开始选.

nth-last-child() 倒着选

第三类

:first-of-type
:last-of-type

第四类

:nth-of-type
:nth-last-of-type

第五类

:root
选择文档根元素.就是 html
:empty
选择元素中连个空格都没有的元素
:not
否定选择器
:only-child
在集合只有一个元素的时候才会生效.
::selection
只能设置两个属性:background,color.

    原文作者:云水摇啊摇
    原文地址: https://segmentfault.com/a/1190000010113393
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞