国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

css3 - css中如何讓第一個和最后一個不被選中?

瀏覽:156日期:2023-07-05 13:47:12

問題描述

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; }

標(biāo)簽: CSS
相關(guān)文章:
主站蜘蛛池模板: 肥东县| 庆城县| 建水县| 宝应县| 明光市| 疏勒县| 昭苏县| 兴宁市| 易门县| 盐源县| 萍乡市| 阳信县| 宜都市| 确山县| 临海市| 麻阳| 雅江县| 卢湾区| 游戏| 上杭县| 伊金霍洛旗| 长顺县| 衡阳市| 巴楚县| 明水县| 西乡县| 雷山县| 牡丹江市| 荣成市| 秀山| 盖州市| 卢氏县| 铜陵市| 六盘水市| 蓬莱市| 枞阳县| 蓝田县| 岳西县| 许昌市| 洛扎县| 儋州市|