My attempt to flip these cards individually has resulted in them all flipping together.
I suspect there may be an error in my JavaScript code.
In the original code, I used images in front and an unordered list in the back, but here I have simplified it to just "Front" and "Back".
$(".flip").click(function() {
$(".card").toggleClass("flipped");
});
.card-container {
display: flex;
}
.card {
width: 300px;
height: 6rem;
margin: 30px;
transform-style: preserve-3d;
transition: transform 1s;
}
.card figure {
margin: 0;
display: block;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.card figure figcaption {
padding: 0 1rem;
backface-visibility: hidden;
border: 1px solid gray;
}
.card button.flip {
position: absolute;
right: 1rem;
margin: 0;
}
.card button.flip {
top: 1rem;
}
.card .back {
transform: rotateY( 180deg);
}
.card.flipped {
transform: rotateY( 180deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card-container">
<div class="card">
<figure class="front">
<figcaption>
<h2>FRONT 1</h2>
<button class="flip">+</button>
</figcaption>
</figure>
<figure class="back">
<figcaption>
<h2>BACK 1</h2>
<button class="flip">-</button>
</figcaption>
</figure>
</div>
<div class="card">
<figure class="front">
<figcaption>
<h2>FRONT 2</h2>
<button class="flip">+</button>
</figcaption>
</figure>
<figure class="back">
<figcaption>
<h2>BACK 2</h2>
<button class="flip">-</button>
</figcaption>
</figure>
</div>
</div>
Could someone point out what could be going wrong here?