first-child & first-of-child

67 阅读1分钟

first-child

first-child 选中一组兄弟元素中的第一个。

demo:第一组 article 元素中的 p 标签被选中。

理解好 first-child 的语义,要不然可能会写出 article:fisrt-child 这种代码。误认为是选中了 article 元素中的第一个元素

first-of-type

first-of-child 组兄弟元素中其类型的第一个元素。

demo:两组 article元素中的 第一个 p 标签都被选中了。