任務(wù)1處問什么不能用按照下面這樣寫?????背景顏色都變成一樣的了 why?
.slider a:nth-of-type(1) {
? ? ? ? ? ? background-color: #02646e;
? ? ? ? ? ? }
? ? ? ? ? ? .slider a:nth-of-type(2) {
? ? ? ? ? ? background-color: #eb0837;
? ? ? ? ? ? }
? ? ? ? ? ? .slider a:nth-of-type(3) {
? ? ? ? ? ? background-color: #67b374;
? ? ? ? ? ? } ? ?
? ? ? ? ? ? .slider a:nth-of-type(4) {
? ? ? ? ? ? background-color: #e6674a;
? ? ? ? ? ? } ? ?
? ? ? ? ? ? .slider a:nth-of-type(5) {
? ? ? ? ? ? background-color: #e61061;
? ? ? ? ? ? }
2016-12-07
:nth-of-type是匹配同類型元素的,可以再復(fù)習(xí)一下這一節(jié)課。再來看這里的html結(jié)構(gòu):
每個<li></li>下只有一個a元素,而你的思路是選擇.slider下的<a>元素。問題在于<a>標(biāo)簽被<li>標(biāo)簽包起來了。
應(yīng)該先匹配li元素,再選擇每一個li下的a元素: ? (n可以是1,2,3,4,5)
2016-04-04
:nth-of-type(n)選擇器匹配同類型中的第n個同級兄弟元素,這里a的同級兄弟元素永遠(yuǎn)都只有一個,就第一個選擇器起作用,其他根本沒用!
2016-03-30
選擇器 .slider a:nth-of-type(1)表示 .slider? a下面的第一個子級,而不是ul的第一個子級