我想知道以下是否可能,在最后半小时搜索它时找不到它所以在这里.
我有一个无序列表
<ul>
<li class="head">Day 1</li>
<li>10:00</li>
<li>12:00</li>
<li class="head">day 2</li>
<li>10:00</li>
<li>14:00</li>
</ul>
<style>
ul li.head {
background-color:green;
}
ul li:hover {
background-color:red;
}
</style>
Run Code Online (Sandbox Code Playgroud)
现在,如果你将鼠标悬停在li.head上,它也会得到一个红色的背景.
所以我的问题是,是否有类似的东西
<style>
ul li.head {
background-color:green;
}
ul li:hover !for li.head {
background-color:red;
}
</style>
Run Code Online (Sandbox Code Playgroud)
我只是想知道在css中是否有这样的东西,我不是在寻找其他解决方案,这不是我的观点.
为了说清楚,我不想像它那样覆盖它
<style>
ul li.head {
background-color:green;
}
ul li:hover {
background-color:red;
}
ul li.head:hover {
background-color:green;
}
</style>
Run Code Online (Sandbox Code Playgroud)
我也不想要
<style>
ul li:hover {
background-color:red;
}
ul li.head {
background-color:green;
}
</style>
Run Code Online (Sandbox Code Playgroud)
我只是想知道在CSS中是否有类似的东西.
注意:你可能会想到为什么你可以简单地用这个代码覆盖它,但我真的简化了这个例子.
你可以试试这个: -
无需覆盖.您可以指定:not()过滤掉不需要的内容.
ul li:not(.head):hover {
background-color:red;
}
Run Code Online (Sandbox Code Playgroud)
IE9下面不支持.