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;
}

 

 

 

 

 

 

posted @ 2017-08-18 15:15  HelenJ  阅读(19243)  评论(0编辑  收藏  举报