css3 - css中如何讓第一個和最后一個不被選中?
問題描述
tr:not(:first-child):hover {background: #ffffdd; }
這樣只能匹配讓第一行鼠標(biāo)移動到上面時背景不變黃
tr:not(:last-child):hover {background: #ffffdd; }
這樣只能匹配讓最后一行鼠標(biāo)移動到上面時背景不變黃
那么,問題來了.請問如何讓第一行和最后一行鼠標(biāo)移動到上面時背景都不變黃呢?
問題解答
回答1:兩個 :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)問題,使用下面的會更安全
.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:以ul為例
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í)只要將第一個和最后一個恢復(fù)原樣覆蓋就行了,那么下面也是可以的
li:hover{ background: #ff0000; } li:first-child:hover{ background: inherit; } li:last-child:hover{ background: inherit; }
相關(guān)文章:
1. 管理員信息修改時的密碼問題2. html5 - 為什么使使用vue cli 腳手架,post-css 沒有自動對css3屬性自動添加瀏覽器前綴呢?3. angular.js - 輸入郵箱地址之后, 如何使其自動在末尾添加分號?4. android - RxJava 中有根據(jù)條件執(zhí)行不同函數(shù)的操作符嗎?5. javascript - 如何使用nodejs 將.html 文件轉(zhuǎn)化成canvas6. java如何生成token?7. javascript - 后臺管理系統(tǒng)左側(cè)折疊導(dǎo)航欄數(shù)據(jù)較多,怎么樣直接通過搜索去定位到具體某一個菜單項(xiàng)位置,并展開當(dāng)前菜單8. javascript - html5的data屬性怎么指定一個function函數(shù)呢?9. 如何解決docker宿主機(jī)無法訪問容器中的服務(wù)?10. mysql - 電商如何存儲營業(yè)額數(shù)據(jù)
