Hello, in this tutorial, I will show you how to create the card flip animation when you hover on the element.
Hello, in this tutorial, I will show you how to create the card flip animation when you hover on the element.
Setting up the HTML Page
To begin, add a div element and apply the card-container class to it.
The approach is to create a box to store the contents of a card. Then we’ll use this box to enable us to hover over on top of it and apply the transforms to the elements inside to do the card flip animation
Add a div element inside the container and apply the card class to it. Inside the card div, add 2 additional div elements, one for the card’s back and one for the front of the card.
Create a CSS file and add it to the page.
<link rel="stylesheet" href="./index.css">
Building the CSS
Go to the CSS file and create the selector for card, card-container, card-front, and card-back.
For card-container set the width and height to 15em and 20em and then set the perspective to 40em. This will allow us to do 3D transforms inside the container.
For card, set:
Now for card-back, give it a background color so we can see it.
For card-front, set the rotation to 180 degrees to start and then set the background color.
We want to rotate the front of the card 180 degrees because everything is facing us by default. Since we want to back of the card to face us, the front of the card needs to be facing the opposite direction.
By setting backface-visibility to hidden, it will hide the mirror version of the element.
To add the flip effect, create another selector for the card-container and then apply the hover pseudo class to it. Since we want the hover effect to affect the card, add the card class after the selector.
Now all we have to do is to set the Y rotation to 180 degrees using transform and the rotateY() function.
Download source code
https://codeible.com/coursefiles/cardflipwithhover