html - 当 CSS 悬停时,如何使我的禁用按钮不改变颜色?

标签 html css

我试过这个 CSS:

html.dark .btn:hover:not(disabled),
html.dark .btn:focus {
  color: #ffffff;
  background-color: #222222;
  *background-color: #151515;
}
html.dark .btn.disabled,
html.dark .btn[disabled] {
  color: red;
  background-color: #222222;
  *background-color: #151515;
}

但是当我将鼠标悬停在按钮上时,我仍然看到颜色从红色变为白色。请注意,它正确地接受了它被禁用的事实。我正在使用:

disabled="disabled"

在我的按钮中。

最佳答案

试试 .btn:hover:not(:disabled),

一个小例子

你的例子没有工作,因为你正在使用 .btn:hover:not(disabled) 你必须使用伪类来实现你需要的 reference pseudo classes

button:hover:not(:disabled){
    color:red;
}
<button>Not disabled</button>
<button disabled>disabled</button>

关于html - 当 CSS 悬停时,如何使我的禁用按钮不改变颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30955433/

相关文章:

css - 无法让页面读取简单 div 的 CSS 页面

css - 如何在 firefox 中调试占位符伪元素?

php - 如何在从 PHP 从数据库中检索数据时将 2 个单元格加入表中?

javascript - 取消选中复选框时如何执行操作?

javascript - 在输入组中引导 5 个 float 标签

html - 如何将相对路径添加到 PIE.htc 文件?

html - 带 Bootstrap 的图像,打破列/格

css - 以句点开始 LESS 变量值

php - MPDF 不显示正确的 CSS

html - 靠近内联元素时图标改变宽度