I have encountered an issue with my CSS
function focusCard(element) {
element.getElementsByClassName("front")[0].classList.toggle("show");
element.getElementsByClassName("back")[0].classList.toggle("show");
}
.box {
cursor: pointer;
width: 270px;
height: 170px;
}
.center {
display: flex;
justify-content: center;
align-items: center;
}
.front {
position: absolute;
width: 270px;
height: 170px;
background-color: #778da9;
transform: perspective(800px);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transition: all 0.5s;
overflow: hidden;
}
.box:hover .front,
.show {
transform: rotateX(180deg);
}
.back {
position: absolute;
width: 270px;
height: 170px;
background: #415a77;
transform: perspective(800px) rotateY(0deg);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transition: all 0.5s;
flex-direction: column;
transform: rotateX(180deg);
}
.box:hover .back,
.show {
transform: rotateX(0deg);
}
<div class="container">
<div class="questions">
<div class="">
<div class="box" onclick="focusCard(this)">
<div class="front center">
<h2>Front #1</h2>
</div>
<div class="back center">
<p>Back #2</p>
</div>
</div>
</div>
</div>
</div>
Everything is working fine on desktop, but there seems to be a problem on mobile devices. When clicking on the front part of the card on mobile, the back appears but does not revert to the front when clicking the back. Can anyone provide assistance with this issue?
Appreciate any tips and advice. Thank you!