Reputation: 111
I have an issue with the background-color transition: If I define the object's background in CSS and then add the transition to it, it works well, but if I do the same in HTML, I does nothing... The codes are:
.container a {
background-color: #333;
transition: background-color 0.2s;
}
.container a:hover {
background-color: red;
}
<div class="container">
<a href="#">Login</a>
<!-- This works well-->
<a href="#" style="background-color: green">Login</a>
<!-- This does not-->
</div>
Any ideas?
Upvotes: 0
Views: 3656
Reputation: 207901
Inline styles have the highest specificity, so your rule isn't being applied. You can get around that by not using inline styles, or applying the dreaded !important
to the rule
.container a {
background-color: #333;
transition: background-color 0.2s;
}
.container a:hover {
background-color: red !important;
}
<div class="container">
<a href="#">Login</a>
<!-- This works well-->
<a href="#" style="background-color: green">Login</a>
<!-- This does not-->
</div>
Upvotes: 4