first-child选择器怎么用?
导读: CSS3:first-child选择器怎么用? :first-child选择器匹配其父元素中的第一个子元素。 语法: 元素:first-child { css样式 } 例:匹配的父元素的第一个元...
CSS3:first-child选择器怎么用?
:first-child选择器匹配其父元素中的第一个子元素。
语法:
元素:first-child
{
css样式
}
例:匹配的父元素的第一个
元素 p:first-child { background-color:yellow; } 注释:所有主流浏览器都支持:first-child选择器。对于IE8及更早版本的浏览器中的:first-child,必须声明。 CSS:first-child选择器的使用示例 示例1:选择每个
中的每个元素并设置其样式,其中的
元素是其父元素的第一个子元素: p:first-childi { background:yellow; }
Iamastrongman.Iamastrongman.
Iamastrongman.Iamastrongman.
效果图: 1.jpg 示例2:每一个- 元素的第一个子元素选择的样式
ul>
:first-child
{
background:yellow;
}
- Coffee
- Tea
- CocaCola
- Coffee
- Tea
- CocaCola
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: first-child选择器怎么用?
本文地址: https://pptw.com/jishu/668429.html