【问题标题】:change css of button when mouse over鼠标悬停时更改按钮的css
【发布时间】:2015-03-31 23:20:55
【问题描述】:
#buttonShareMap:disabled {
    background:black;
}

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

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

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

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

不能让它工作......有什么想法吗? ta

此外,当鼠标悬停在禁用的按钮上时,光标将变为鼠标悬停在手上。我希望它保留为光标,并且仅在启用按钮时才变为鼠标悬停?

【问题讨论】:

  • 一旦元素被禁用,我相信它不再引发 any 事件,因此hover 不会触发它。
  • 你试过用 ":active" 了吗?
  • 使用 !important 覆盖

标签: javascript jquery html css


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-28
      • 2012-08-16
      • 1970-01-01
      • 2016-06-23
      • 2013-09-10
      • 1970-01-01
      • 2011-11-07
      • 2016-12-11
      相关资源
      最近更新 更多