This question has already been answered:
When you direct it, it turns over and on the back side the text is written
This question has already been answered:
When you direct it, it turns over and on the back side the text is written
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
We will need:
The element of the card, with position: relative , when you hover on which all the magic will occur.
Back ( div.card__back ), which will be deployed during this event. Position: absolute and z-index: 0 to be behind the top block.
And, accordingly, the top element ( div.card__front ), which collapses when you hover the user. BUT, z-index: 1 just will not work, we add position: relative
Now the magic itself. Initially, the rear block in us has a transform: rotatY(-180deg) , which means that it is rotated about the Y-axis by 180 degrees, and it is reflected from our viewing angle. And when hovering, the upper one is already reflected at 180, and the rear one comes to a normal state, but this is just an animation, since their display switches the z-index .
It remains only to explain to the browser how to draw this animation, and I added a business cube for the animation animation - transition: transform .3s cubic-bezier(.2,.85,.4,1.275) . And also indicate one property that is rarely used, because it is responsible for displaying the back side of the object backface-visibility: hidden
.card { position: relative; width: 300px; height: 100px; color: white; } .card__front{ z-index: 1; position: relative; background-color: cyan; height: 100%; text-align: center; backface-visibility: hidden; transition: transform .3s cubic-bezier(.2,.85,.4,1.275); } .card__back{ z-index: 0; position: absolute; top: 0; width: 100%; height: 100%; text-align: center; backface-visibility: hidden; background-color: orange; transform: rotateY(-180deg); transition: transform .3s cubic-bezier(.2,.85,.4,1.275); } .card:hover .card__back { transform: rotateY(0deg); z-index: 2; } .card:hover .card__front { transform: rotateY(180deg); z-index: -1; } <div class="card"> <div class="card__front">123</div> <div class="card__back">321</div> </div> Source: https://ru.stackoverflow.com/questions/812438/
All Articles