云企logo

first-child 选择器 定义首个子元素样式

更新日期:2022-06-19  

实例:选择属于其父元素的首个子元素的每个 <p> 元素,并为其设置样式:

p:first-child{ 
background-color:yellow;
}

注释:对于IE8及更早版本的浏览器中的 :first-child,需声明 <!DOCTYPE>。

例子 1

选择每个 <p> 中的每个 <i> 元素并设置其样式,其中的 <p> 元素是其父元素的首个子元素:

p:first-child i{
background:yellow;
}

例子 2

选择列表中的首个 <li> 元素并设置其样式:

li:first-child{
background:yellow;
}

 

上一篇:dedecms“更新系统缓存”清理沉积缓存的功能

下一篇:织梦自定义表单怎么导出到excel?
首页