鼠标悬停时更改按钮的 CSS

change css of button when mouse over

本文关键字:按钮 CSS 悬停 鼠标      更新时间:2023-09-26
#buttonShareMap:disabled {
    background:black;
}

如果禁用,会将我的按钮的颜色更改为黑色。

但是,如果禁用,并且用户将光标悬停在按钮上,它将变为蓝色,这是启用按钮时通常的颜色class="edit blue btn".....

我想在禁用按钮时始终保持黑色...所以是这样的:

.buttonShareMap:disabled:hover
{
    background:black;
}

无法让它工作...有什么想法吗?呵��

此外,光标将变为鼠标悬停在手上...当按住禁用按钮时。我希望它保留为光标,只有在启用按钮时才更改为鼠标悬停?

您可以使用

!important,这应该可以工作。背景可能被级联覆盖了。 最好找出位置并纠正它而不是!important但如果您需要一个快速而肮脏的解决方案,它将起作用。 此外,您可以将光标设置为禁用时的默认光标。 CSS加在一起将是:

#buttonShareMap:disabled {
  background:black !important;
  cursor:default;
}
A disabled button wont be able to catch the JS events like hover, mouseover etc. If you want to change your disabled button color, you can directly do it using CSS. You can do something like:
<style>
input.button:disabled{ background: #000; color: #FFF; cursor: default;}
</style>
<input type="button" class="button" value="Button" disabled>
If the background color is not picked you can add an !important with the CSS rule.