概述
CSS3—first-child 不起作用的原因
1、first-child、last-child、nth-child(n)、nth-child(2n)、nth-child(2n-1)、nth-child(odd)、nth-child(even)、nth-last-child(3)(倒数第三个)
注意点: 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型。
1、先找到该伪类调用者(元素)的父类
2、其次找到父类下的第n个子元素
3、最后看该子元素是不是1中的伪类调用者,如果是,则应用css,否则不应用
有时候first-child或者nth-child(1) 不起作用的原因,如下:
/*此时first-child不起作用,是因为.tap_con的父元素win的第一个子元素是.top,此时找到第一个子元素,但是其并不是.tab_con*/
<style>
.tab_con:first-child{
background:#090 !important;
}
.tab_con:nth-child(1){
background:#090 !important;
}
</style>
<div id="win">
<div class="top">
</div>
<div class="tab_con">
</div>
<div class="tab_con">
</div>
</div>
最后
以上就是无心路灯为你收集整理的first-child 不起作用的原因的全部内容,希望文章能够帮你解决first-child 不起作用的原因所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复