I'm trying to create a flip card functionality that works on hover in desktop view while on click in mobile view.
I'm able to achieve both using checkbox and entirely using CSS.
Here's the code snippet:
.flip-card {
width: 150px;
height: 180px;
margin: 1em;
perspective: 1500px;
}
.flip-card .flip-card-inner {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.8s cubic-bezier(0.75, 0, 0.85, 1);
}
.more {
display: none;
}
.more:checked ~ .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
transform-style: preserve-3d;
border-radius: 6px;
}
.inner {
height: 100%;
display: grid;
padding: 1.5em;
}
.flip-card-front {
background-color: #2980b9;
}
.flip-card-back {
transform: rotateY(180deg);
background-color: #fff;
border: 2px solid #f0f0f0;
}
@media screen and (min-width: 900px){
.flip-card-inner:hover {
transform: rotateY(180deg);
}
}
<div class="flip-card col-6">
<input type="checkbox" id="card1" class="more" aria-hidden="true">
<div class="flip-card-inner">
<label for="card1" aria-hidden="true">
<div class="flip-card-front" style="background-color: rgba(96,132,38,0.4); box-shadow: 3px 3px 4px rgba(0, 0, 0, 0.4),
-3px -3px 4px rgba(255, 255, 255, 1);">
<div class="font-weight-bold flip-card-front-book-title ml-2 mb-2">Outliers</div>
<div class="font-weight-bold flip-card-front-book-author ml-2" style="color: #A2671A;"> <span
class="text-muted">By</span> Malcolm Gladwell</div>
</div>
</label>
<label for="card1" aria-hidden="true">
<div class="flip-card-back" style="box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.4),
-3px -3px 4px rgba(255, 255, 255, 1);">
<div>
<h5 >Added by</h5>
<strong >Jitesh</strong>
</div>
</div>
</label>
</div>
</div>
<div class="flip-card col-6 ">
<input type="checkbox" id="card2" class="more" aria-hidden="true">
<div class="flip-card-inner">
<label for="card2" aria-hidden="true">
<div class="flip-card-front" style="background-color: rgba(96,132,38,0.4); box-shadow: 3px 3px 4px rgba(0, 0, 0, 0.4),
-3px -3px 4px rgba(255, 255, 255, 1);">
<div class="font-weight-bold flip-card-front-book-title ml-2 mb-2">Shoe Dog</div>
<div class="font-weight-bold flip-card-front-book-author ml-2" style="color: #A2671A;"> <span
class="text-muted">By</span> Phil Knight</div>
</div>
</label>
<label for="card2" aria-hidden="true">
<div class="flip-card-back" style="box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.4),
-3px -3px 4px rgba(255, 255, 255, 1);">
<div>
<h5 >Added by</h5>
<strong >Ishant</strong>
</div>
</div>
</label>
</div>
</div>
I am displaying multiple cards and using their unique IDs for flip event on mobile view. Now, I need to add a functionality to flip the card back once any other card is clicked or I click anywhere else. (Only for mobile view). Currently I have to manually click each card to flip it back to orignal.
I'm looking for CSS based solution if possible.
P.S. If it's not possible using pure CSS, please provide a working solution using jquery as I'm new to it.