我需要“如果我的班级被禁用,请勿这样做” CSS 选择器的种类
我目前有以下 CSS:
a.enabled:hover { background-color: #f9f9f9; border: 1px solid #ddd; }
代码:
<div><a class="enabled" ......>07</a></div>
<div><a class="enabled" ....... >08</a></div>
<div><a class="disabled" >09</a></div>
<div><a class="enabled" ...... >10</a></div>
<div><a class="enabled" .......>11</a></div>
当我将鼠标悬停在“启用”链接上时,背景颜色会发生变化。当我将鼠标悬停在“禁用”链接上时,什么也没有发生。
我想通过删除出现在这么多行(超过 200 行)中的所有 class="enabled" 文本来减少页面大小。像这样的东西。
之后:
<div><a ........>07</a></div>
<div><a ....... >08</a></div>
<div><a class="disabled" >09</a></div>
<div><a ...... >10</a></div>
<div><a .......>11</a></div>
有没有办法用 CSS 做到这一点?我只是希望如果链接具有“禁用”状态,则悬停不会更改背景颜色。
I currently have the following CSS:
a.enabled:hover { background-color: #f9f9f9; border: 1px solid #ddd; }
Code:
<div><a class="enabled" ......>07</a></div>
<div><a class="enabled" ....... >08</a></div>
<div><a class="disabled" >09</a></div>
<div><a class="enabled" ...... >10</a></div>
<div><a class="enabled" .......>11</a></div>
When I hover over an "enabled" link then the background color changes. When I hover over a "disabled" link then nothing happens.
I would like cut down on the size of my page by removing all the class="enabled" text that appears on so many lines (more than 200). Something like this.
After:
<div><a ........>07</a></div>
<div><a ....... >08</a></div>
<div><a class="disabled" >09</a></div>
<div><a ...... >10</a></div>
<div><a .......>11</a></div>
Is there a way I can do this with CSS? I just want the hover not to change the background-color if the link has a "disabled" status.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您将使用的选择器是
权衡是浏览器兼容性 - IE < 9 不支持
:not()
。作为解决方法,如果您可以定义默认背景颜色,则可以将覆盖规则与这两个规则结合使用:...或者仅坚持现有的
.enabled
和.disabled解决方案。
The selector you will use is
The trade-off is browser compatibility - IE < 9 does not support
:not()
. As a workaround you can use an override rule with these two rules instead, if you can define a default background color:... or just stick to your existing
.enabled
and.disabled
solution.默认颜色相同
为 a.disalbe:hover 添加一条 css 规则,其颜色与JsBin 中的演示
Add a css rule for a.disalbe:hover that has the same colour as the default that you have for a
demo in JsBin
尝试使用 css
:not
选择器。Try using the css
:not
selector.您是否可以将样式应用于所有
div a
,然后在应用.disabled
类时撤消它?像这样的东西
could you just apply a style to all
div a
and then undo it when the.disabled
class is applied?Something like
你试过这个吗?或者像这样:
...然后你只在 HTML 中使用启用的类
Did you tried this? Or something like this:
...and then you only use the enabled class in your HTML