How to animate background-color of an element on mouse hover using CSS
transition
You can use the CSS3 transition property to smoothly animate the background-color of an element on mouseover, such as a hyperlink or a button.
background-color
Let's try out an example to understand how it basically works:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>CSS Smooth Animation of Element's Background Color</title> <style> a { color: #fff; border: none; margin: 20px; padding: 10px 20px; display: inline-block; font: bold 18px sans-serif; background: #fd7c2a; text-decoration: none; -webkit-transition: background 1s; /* For Safari 3.0 to 6.0 */ transition: background 1s; /* For modern browsers */ } a:hover { background: #3cc16e; } </style> </head> <body> <p><a href="#">Hover on me</a></p> </body> </html>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Use the CSS3
transitionpropertyYou can use the CSS3
transitionproperty to smoothly animate thebackground-colorof an element on mouseover, such as a hyperlink or a button.Let's try out an example to understand how it basically works:
need an explanation for this answer? contact us directly to get an explanation for this answer