我有一个无序列表的项目,是交替的背景颜色通过:nth-child(even)。当鼠标通过:hover悬停在这些项目上时,它们也会以不同的背景色高亮显示。
我需要能够指定项目,使他们保持交替的背景色,但不要高亮显示在悬停。
我还没想出办法来做这个。
下面是一个简短的例子:http://jsfiddle.net/kjk8L/2/
发布于 2014-02-18 22:58:33
好的,所以听起来(从下面的评论中)你想要一个类,它不盘旋,但仍然保持交替的背景。
最简单的方法是简单地定义一个类并将它排除在悬浮css中,如下所示:
ul li:not(.special):hover {
background-color:blue;
}这将使得悬停适用于除“特殊”类之外的所有东西。
工作小提琴
发布于 2014-02-18 22:57:54
向第n个子级(偶数)添加一个悬停样式,如下所示
ul li:nth-child(even) {
background-color: grey;
}请看最新的小提琴。http://jsfiddle.net/kjk8L/5/
发布于 2014-02-18 22:58:26
我就是这么做的,希望这能帮上忙。
ul li:nth-child(even) {
background-color: #efffef;
}
ul li:nth-child(even):hover {
background-color: #dfd;
}
/* you can skip styling of the odd children if you don't want to */
ul li:nth-child(odd) {
background-color: #efefff;
}
ul li:nth-child(odd):hover {
background-color: #ddf;
}https://stackoverflow.com/questions/21867282
复制相似问题