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