鼠标悬停时改变按钮的CSS

时间:2015-03-31 14:35:08

标签: javascript jquery html css

#buttonShareMap:disabled {
    background:black;
}
如果禁用,

会将我的按钮颜色更改为黑色。

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

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

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

无法让它工作......任何想法? TA

此外,当光标停在禁用按钮上时,光标会变为手上的鼠标。我希望它保持为光标,只有在按钮启用时才会改为鼠标移动?

2 个答案:

答案 0 :(得分:2)

您可以使用!important,这应该有效。背景可能可能是由级联写的。最好找出位置并更正{而不是!important但是如果你需要一个快速而肮脏的解决方案它会起作用。此外,您可以将光标设置为禁用时的默认光标。所有CSS都将是:

#buttonShareMap:disabled {
  background:black !important;
  cursor:default;
}

答案 1 :(得分:0)

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.