CSS3---first-child或者nth-child(1) 不起作用的原因


一、零碎
     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*/
   <div id="win">
        <div class="top">
        </div>
        <div class="tab_con">
        </div>
        <div class="tab_con">
        </div>
   </div>
 
==========================================================
.tab_con:first-child{
    background:#090 !important;
}
==========================================================
.tab_con:nth-child(1){
    background:#090 !important;
}

 

 

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM