css3 - css中如何讓第一個和最后一個不被選中?
問題描述
tr:not(:first-child):hover {background: #ffffdd; }
這樣只能匹配讓第一行鼠標移動到上面時背景不變黃
tr:not(:last-child):hover {background: #ffffdd; }
這樣只能匹配讓最后一行鼠標移動到上面時背景不變黃
那么,問題來了.請問如何讓第一行和最后一行鼠標移動到上面時背景都不變黃呢?
問題解答
回答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 似乎更穩定 */ 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 更正
預覽好了。 底部
或者 :not(class)如果上面的代碼出現問題,使用下面的會更安全
.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>預覽
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; }
其實只要將第一個和最后一個恢復原樣覆蓋就行了,那么下面也是可以的
li:hover{ background: #ff0000; } li:first-child:hover{ background: inherit; } li:last-child:hover{ background: inherit; }
相關文章:
1. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. Java:密碼包(加密和解密)。無效的密鑰錯誤3. css - 微信小程序點擊展開,再次點擊收回4. 點擊頁面就自動輸入到mysql.求解5. macos - mac下docker如何設置代理6. css - vue.js的vue單文件組件style中的scoped屬性無效7. angular.js - 在ng-option 里使用過濾器無效8. node.js - 求問nw.js開發桌面版,其js計算性能如何?9. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?10. thinkphp5.1學習時遇到session問題
