0

Hover not working CSS

Why my hover button not working in css? https://code.sololearn.com/W5WRuhW7D7U2/?ref=app

10th Apr 2020, 12:04 PM
Souptik Nath
Souptik Nath - avatar
6 Réponses
+ 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 ;)
10th Apr 2020, 1:18 PM
visph
visph - avatar
+ 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; }
10th Apr 2020, 12:25 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
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.
10th Apr 2020, 12:12 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
0
Aaron Eberhardt So what should I do now?
10th Apr 2020, 12:14 PM
Souptik Nath
Souptik Nath - avatar
0
Aaron Eberhardt What is the problem if we use ! important property??
10th Apr 2020, 12:30 PM
Souptik Nath
Souptik Nath - avatar
10th Apr 2020, 1:54 PM
Aaron Eberhardt
Aaron Eberhardt - avatar