Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to make something with css, and I found out that hover doesn't work on disabled elements.

What I have tried:

html:
<div class='text'>
     hi
</div>

<button id='btn' disabled>hi</button>

css:
#text {
  display: none; 
}
#btn:hover + #text{
  display: block;
}
Posted
Updated 1-Dec-19 21:24pm
Comments
Richard Deeming 27-Nov-19 14:48pm    
Disabled buttons are generally a bad idea anyway:
Disabled buttons suck - Axess Lab[^]

Hi
Hover works on disabled button. i have tried to run your code and found a one syntax mistake. but then by solving it, your code is working now. take a look here: Hover over disabled button[^]
<div class='text'>
     hi
</div>
you have used text as a class in above div but when you apply hover over disabled button you have applied text as an id, that's why your code is not working properly.

Do this correction. and you will get proper output. let me know if you have any query.
Hope this will help you. Thank you.
 
Share this answer
 
Comments
Richard Deeming 29-Nov-19 8:00am    
Good catch!

It's also worth noting that the text <div> needs to come after the button in the HTML markup. In the question, it looks like it was before the button.
[no name] 29-Nov-19 8:23am    
right!! that also can be a reason.
You would be better served with using events that you control.

Since it's a disabled control you cannot use onfocus, but you can use onmouseover and onmouseout. From there you can do whatever you want for the hover event.
 
Share this answer
 
just use :enabled with :hover to solve your problem
Example : -
#btn:hover:enabled {
    // it will work only on that time when button will be enabled.
}
 
Share this answer
 
button:hover:enabled{
    /*your styles*/
}
button:active:enabled{
    /*your styles*/
}


just try this css code and see what's the output
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900