css3 - css中如何讓第一個(gè)和最后一個(gè)不被選中?
問題描述
tr:not(:first-child):hover {background: #ffffdd; }
這樣只能匹配讓第一行鼠標(biāo)移動(dòng)到上面時(shí)背景不變黃
tr:not(:last-child):hover {background: #ffffdd; }
這樣只能匹配讓最后一行鼠標(biāo)移動(dòng)到上面時(shí)背景不變黃
那么,問題來了.請(qǐng)問如何讓第一行和最后一行鼠標(biāo)移動(dòng)到上面時(shí)背景都不變黃呢?
問題解答
回答1:兩個(gè) :not寫在一起就好了呀
.a { width: 80px; height:60px; background:#333; border: #eee solid 1px;}.a:not(:first-of-type):not(:last-of-type):hover { /* First-Of-Type 似乎更穩(wěn)定 */ background: #ffffdd;}
<p class='a'></p><p class='a'></p><p class='a'></p><p class='a'></p><p class='a'></p>2016.9.24 更正
預(yù)覽好了。 底部
或者 :not(class)如果上面的代碼出現(xiàn)問題,使用下面的會(huì)更安全
.b { width: 80px; height:60px; background:#333; border: #eee solid 1px;}.b:not(.b-n):hover { background: #ffffdd;}
<p class='b b-n'></p><p class='b'></p><p class='b'></p><p class='b'></p><p class='b b-n'></p>預(yù)覽
http://codepen.io/KZ-DSF/pen/...
回答2:以u(píng)l為例
li:not(:first-child):hover{ background: #ff0000; } li:not(:last-child):hover{ background: #ff0000; } li:first-child:hover{ background: inherit; } li:last-child:hover{ background: inherit; }
其實(shí)只要將第一個(gè)和最后一個(gè)恢復(fù)原樣覆蓋就行了,那么下面也是可以的
li:hover{ background: #ff0000; } li:first-child:hover{ background: inherit; } li:last-child:hover{ background: inherit; }
相關(guān)文章:
1. python - scrapy url去重2. Python從URL中提取域名3. node.js - 微信小程序websocket連接問題4. 實(shí)現(xiàn)bing搜索工具urlAPI提交5. Python中使用超長(zhǎng)的List導(dǎo)致內(nèi)存占用過大6. python - Django有哪些成功項(xiàng)目?7. python執(zhí)行cmd命令,怎么讓他執(zhí)行類似Ctrl+C效果將其結(jié)束命令?8. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)9. 數(shù)據(jù)庫 - Mysql的存儲(chǔ)過程真的是個(gè)坑!求助下面的存儲(chǔ)過程哪里錯(cuò)啦,實(shí)在是找不到哪里的問題了。10. 鏈接圖片時(shí),鏈接不成功
