一、零碎
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; }
