Code for Transition
Let's look at a straightforward example where we make a button's hover effect. The button will gracefully change in width and background color as the user hovers over it.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Transition Example</title> <style> .transition-button { padding: 10px 20px; background-color: #4CAF50; /* Green */ color: white; border: none; transition-property: background-color, width; transition-duration: 0.5s; transition-timing-function: ease-in-out; } .transition-button:hover { background-color: #555; /* Darker gray */ width: 150px; /* Increase width */ } </style> </head> <body> <button class="transition-button">Hover over me!</button> </body> </html> |
Explanation of code
HTML structure
CSS Styling
Code for Transition
Let's look at a straightforward example where we make a button's hover effect. The button will gracefully change in width and background color as the user hovers over it.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Transition Example</title> <style> .transition-button { padding: 10px 20px; background-color: #4CAF50; /* Green */ color: white; border: none; transition-property: background-color, width; transition-duration: 0.5s; transition-timing-function: ease-in-out; } .transition-button:hover { background-color: #555; /* Darker gray */ width: 150px; /* Increase width */ } </style> </head> <body> <button class="transition-button">Hover over me!</button> </body> </html> |
Explanation of code
HTML structure
CSS Styling
Copyrights © 2024 letsupdateskills All rights reserved