How to exclude particular class name in CSS selector?(如何在 CSS 选择器中排除特定的类名?)
问题描述
当用户将鼠标悬停在类名为 "reMode_hover"
的元素上时,我正在尝试应用背景色.
I'm trying to apply background-color when a user mouse hover the element whose class name is "reMode_hover"
.
但如果元素 also 有 "reMode_selected"
注意:我只能使用 CSS 而不是 javascript,因为我在某种有限的环境中工作.
Note: I can only use CSS not javascript because I'm working within some sort of limited environment.
澄清一下,我的目标是在悬停时为第一个元素着色,而不是第二个元素.
To clarify, my goal is to color the first element on hover but not the second element.
HTML
<a href="" title="RGVzaWdu" class="reMode_design reMode_hover">
<span>Design</span>
</a>
<a href="" title="RGVzaWdu"
class="reMode_design reMode_hover reMode_selected">
<span>Design</span>
</a>
我在下面尝试过,希望第一个定义有效,但事实并非如此.我做错了什么?
I tried below hoping the first definition would work but it is not. What am I doing wrong?
CSS
/* do not apply background-color so leave this empty */
.reMode_selected .reMode_hover:hover
{
}
.reMode_hover:hover
{
background-color: #f0ac00;
}
推荐答案
一种方法是使用多类选择器(没有空格,因为那是后代选择器):
One way is to use the multiple class selector (no space as that is the descendant selector):
.reMode_hover:not(.reMode_selected):hover
{
background-color: #f0ac00;
}
<a href="" title="RGVzaWdu" class="reMode_design reMode_hover">
<span>Design</span>
</a>
<a href="" title="RGVzaWdu"
class="reMode_design reMode_hover reMode_selected">
<span>Design</span>
</a>
这篇关于如何在 CSS 选择器中排除特定的类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 CSS 选择器中排除特定的类名?


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01