css :first-child选择器用于匹配其父元素中的第一个子元素;即只有当元素是其父元素的第一个子元素时才会匹配元素。

CSS3 :first-child选择器怎么用?
:first-child 选择器匹配其父元素中的第一个子元素。
语法:
元素:first-child
{
css样式
}例:匹配
的父元素的第一个
元素
立即学习“前端免费学习笔记(深入)”;
p:first-child
{
background-color:yellow;
}注释:所有主流浏览器都支持 :first-child 选择器。对于 IE8 及更早版本的浏览器中的 :first-child,必须声明 。
CSS :first-child选择器的使用示例
示例1:选择每个
中的每个 元素并设置其样式,其中的
元素是其父元素的第一个子元素:
I am a strong man. I am a strong man.
I am a strong man. I am a strong man.
效果图:

示例2:每一个
- 元素的第一个子元素选择的样式
- Coffee
- Tea
- Coca Cola
- Coffee
- Tea
- Coca Cola
效果图:











