:first-child
:first-child表示在一组兄弟元素中的第一个元素。
语法:
E:first-child{sRules}
:first-child是一个伪类,它适用于任何元素,表示在一组兄弟元素中的第一个元素。
:first-childCSS pseudo-class表示在一组兄弟元素中的第一个元素。
/* selects any
that is the first element among its siblings */p:first-child{color: lime;}

Note:最初定义时,所选元素必须有一个parent。而从选择器 Level 4 开始,parent不再是必须的。
浏览器支持
例子
在上述代码中,如果我们要设置第一个li的样式,那么代码应该写成li:first-child{sRules},而不是ul:first-child{sRules}。
this text is selected!
this text isn't selected.