CSS Visual Effect: Image Hover Animation using CSS
In the realm of web development, creating visually engaging and interactive user experiences is paramount. One way to achieve this is through the implementation of image animations. In this blog post, we'll delve into a simple yet effective example of animating an image using HTML and CSS. The focus will be on creating a dynamic effect that catches the user's attention and adds a touch of vibrancy to the web page.
Also Read: Neumorphism Profile Card using HTML and CSS only
With the combination of basic HTML structure and CSS, we'll explore how to infuse life into a static image. By the end of this tutorial, you'll have the knowledge to incorporate similar animations into your projects, elevating the overall user engagement and aesthetic appeal of your websites.
HTML Structure
<div class="container">
<div class="img"></div>
</div>
Here, we've defined a container with the class "container" and nested a div with the class "img" inside it. This structure provides a clean foundation for our animated image.
CSS Styling
Now, let's dive into the CSS styling to enhance the visual appeal of our container and implement the image animation. We'll style both the container and the image to create an engaging visual effect.
.container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
min-width:350px;
}
.img {
width: 300px;
height: 180px;
background: url('https://i.ibb.co/BcbW7PY/img.jpg');
background-repeat: no-repeat;
background-size: cover;
cursor: pointer;
border-radius: 10px;
}
.img:hover {
animation: imageAnimation 1.5s linear infinite alternate;
}
@keyframes imageAnimation {
from {
filter: hue-rotate(0deg);
}
to {
filter: hue-rotate(360deg);
}
}
filter: hue-rotate(0deg); to filter: hue-rotate(360deg): Rotates the hue from 0 to 360 degrees, creating a color-shifting effect.
This CSS code creates an engaging visual experience where the image undergoes a subtle color rotation on hover. Feel free to customize the values according to your preferences and replace the image path with your desired image.
Also Read: Bottom Navigation Menu using HTML CSS and JS
Feel free to explore additional CSS properties and values to further enhance and customize this animation. Thank you for joining us on this journey into creating an engaging and dynamic image effect with CSS.