作者:减肥瘦身666 | 来源:互联网 | 2020-09-09 20:27
CSS :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:每一个
效果图:
以上就是CSS3 :first-child选择器怎么用的详细内容,更多请关注 第一PHP社区 其它相关文章!