Q:

How to animate background-color of an element on mouse hover using CSS

0

How to animate background-color of an element on mouse hover using CSS

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the CSS3 transition property

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.

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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

HTML / CSS Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to transform image size on mouse hover without... >>
<< How to animate text color on mouse hover using CSS...