To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.
To solve the issue, you need to go over the CSS hover code to establish if you use the right selector. As well, ensure you use an opening curly bracket ({) after each selector and a closing curly bracket (}) at the end of the property list.
You can use :enabled pseudo-class, but notice IE<9
does not support it:
button:hover:enabled{
/*your styles*/
}
button:active:enabled{
/*your styles*/
}
.button:active:hover:not([disabled]) {
/*your styles*/
}
You can try this..
Why not using attribute "disabled" in css. This must works on all browsers.
button[disabled]:hover {
background: red;
}
button:hover {
background: lime;
}
If you are using LESS
or Sass
, You can try this:
.btn {
&[disabled] {
opacity: 0.6;
}
&:hover, &:active {
&:not([disabled]) {
background-color: darken($orange, 15);
}
}
}
In sass (scss):
button {
color: white;
cursor: pointer;
border-radius: 4px;
&:disabled{
opacity: 0.4;
&:hover{
opacity: 0.4; //this is what you want
}
}
&:hover{
opacity: 0.9;
}
}
Use the lightest touch: overriding via rule order.
.btn {
/* base styles */
}
.btn:hover {
color: red;
}
.btn:active {
color: green;
}
.btn:disabled {
color: #aaa;
}
The trick is the order -- apply all the non-disabled states first, makes sure they all have the same specificity, and do disabled last, with the same specificity.
This won't work for a class added to links, or non-interactive elements, which don't have the disabled
property.
(Edited to remove higher-specificity rules, and messing with pointer-events
)
One way is to add a partcular class while disabling buttons and overriding the hover and active states for that class in css. Or removing a class when disabling and specifying the hover and active pseudo properties on that class only in css. Either way, it likely cannot be done purely with css, you'll need to use a bit of js.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With