0
Hover not working CSS
Why my hover button not working in css? https://code.sololearn.com/W5WRuhW7D7U2/?ref=app
6 odpowiedzi
+ 2
If you use !important the precedence of the rule becomes higher than any others, and you couldn't no more update the value by setting the style attribute dynamically with JS...
You better have to augment more "naturally" the selector precedence (by adding specifities to the selector).
Anyway, if I remove both !important from your #main button:hover css rule, the :hover effect works fine... doesn't know what you tried to fix, so ;)
+ 1
The easiest solution would be to write:
button:hover{
background-color: #ffffff !important;
}
In a real project you probably don't want every button to behave like this. So you could create a class called "hover-button" for example and write this:
.hover-button:hover{
background-color: #ffffff !important;
}
0
The "button:hover" selector has less priority than the "#main button" selector and therefore the hover does not override the background-color attribute. To solve this you could add !important to the CSS instructions in the :hover selector. But I wouldn't recommend using !important too often in a real project or website.
0
Aaron Eberhardt So what should I do now?
0
Aaron Eberhardt What is the problem if we use ! important property??
0
This article might help you:
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity