I have created some interactive flip cards using CSS and HTML with transitions
Currently, when you hover over a card, it flips and enlarges. However, I am facing an issue with positioning the hovered card on top using z-index and relative position due to the CSS transform property. Is there a way to solve this problem?
My goal is to ensure that the card being hovered over always appears on top.
/* Styling for the flip card container */
.flip-card {
background-color: transparent;
width: 180px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px; /* You can remove this for a simpler effect */
}
/* Container for front and back sides of the card */
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
/* Flip animation on hover */
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg) scale(1.3);
}
/* Front and back side positions */
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
/* Front side styling */
.flip-card-front {
background-color: #bbb;
color: black;
z-index: 1;
}
/* Back side styling */
.flip-card-back {
z-index: 999;
background-color: dodgerblue;
color: white;
transform: rotateY(180deg);
}
<div class="flip-card" style="float:left">
<div class="flip-card-inner">
<div class="flip-card-front">
<div style="position:relative; z-index:1">
<img src="img_avatar.png" alt="Avatar" style="width:300px;height:300px;">
</div>
</div>
<div class="flip-card-back">
<div style="position:relative; z-index:1">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
</div>