This code snippet creates a split image effect on hover using CSS. It uses the clip-path
property to divide the image into four equal parts, and then uses the transform
property to move and rotate the parts on hover.
You can use this code snippet to create a visually appealing and engaging hover effect for images. Furthermore, it can be used on any type of image, but it is particularly well-suited for images with a lot of detail.
How to Create Split Image Effect On Hover Using CSS
1. Begin by creating the HTML structure. Copy the following code, which includes a container <div>
with four nested <span>
elements. These spans will represent the segments of your image.
<div class="image"> <span></span> <span></span> <span></span> <span></span> </div>
2. Now, style each <span>
element with background images and clip-path properties. These properties determine the shape and position of each segment. Implement hover effects to induce dynamic transformations. Each segment gracefully translates and rotates, creating a captivating animation on hover.
* { margin: 0; padding: 0; box-sizing: border-box; } body { height: 100vh; background: #012; display: grid; place-items: center; } .image { width: 500px; height: 350px; position: relative; cursor: pointer; } .image span { position: absolute; background: url(https://picsum.photos/id/182/2896/1944) no-repeat center/cover; inset: 0; transition: 0.6s ease-in-out; } span:nth-child(1) { clip-path: polygon(0 0, 50% 0, 50% 50%, 0 50%); transition-delay: 0; } span:nth-child(2) { clip-path: polygon(50% 0, 100% 0, 100% 50%, 50% 50%); transition-delay: 0.25s; } span:nth-child(3) { clip-path: polygon(0 50%, 50% 50%, 50% 100%, 0 100%); transition-delay: 0.5s; } span:nth-child(4) { clip-path: polygon(50% 50%, 100% 50%, 100% 100%, 50% 100%); transition-delay: 0.75s; } /* Hover Effects */ .image:hover span:nth-child(1) { transform: translate(-40px, -60px) rotate(-15deg); } .image:hover span:nth-child(2) { transform: translate(40px, -100px) rotate(25deg); } .image:hover span:nth-child(3) { transform: translate(-40px, 80px) rotate(15deg); } .image:hover span:nth-child(4) { transform: translate(40px, 80px) rotate(-15deg); }
Feel free to customize the dimensions, positions, and hover effects to align with your creative vision. Experiment with different images and transition timings to achieve the desired visual impact.
That’s all! hopefully, you have successfully created Split Image On Hover Using Css. If you have any questions or suggestions, feel free to comment below.
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.