Skip to content

Instantly share code, notes, and snippets.

@yorickshan
Last active July 5, 2019 03:39
Show Gist options
  • Save yorickshan/d9b28ac91a7c990ae8360a0aa81a05aa to your computer and use it in GitHub Desktop.
Save yorickshan/d9b28ac91a7c990ae8360a0aa81a05aa to your computer and use it in GitHub Desktop.

[element]:first-child 的着眼点在于 first-child

p:first-child先找到第一个子元素, 再看它是不是 p 元素, 是则匹配成功, 否则匹配失败

[element]:first-of-type 的着眼点在于 element

p:first-of-type直接去匹配子元素中的第一个 p 元素

类似选择器 :last-child 和 :last-of-type、:nth-child(n) 和 :nth-of-type(n) 也可以这样去理解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment