3D Rotating Card

Using backface-visibility, transform, transform-style: preserve-3d, perspective, perspective-origin, repeating-linear-gradient

by Konstantin Rouda

HTML

<div class="o-card">
      <div class="o-card__side o-card__side--front">
          <span class="o-card__suit">&clubs;</span>
      </div>
      <div class="o-card__side o-card__side--back"></div>
    </div>

CSS

HTML {
  /*using system font-stack*/
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 115%; /*~18px*/
  font-size: calc(16px + (30 - 16) * (100vw - 300px) / (1300 - 300) );
  line-height: 1.5;
  box-sizing: border-box;
}

body {
  min-height: 90vh;
  background-color: white;
  color: #444;
}

*, *::before, *::after {
  box-sizing: inherit;
  color: inherit;
}


/*Actual Style*/
.o-card {
  position: relative;
  width: 14.5rem; height: 18.75rem;
  margin: 1rem auto 0;
  border: 2px solid rgb(108, 112, 116);
  border-radius: .17rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .15);
  transform-style: preserve-3d;
  transition: transform 1s linear;
}

.o-card__side {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  backface-visibility: hidden;
}


.o-card__side--front {
  transform: rotateY(180deg);
  background: rgba(255, 255, 255, .9);
}


.o-card__side--back {
  background-color: rgb(156, 161, 165);
  background-image: repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(52, 139, 178, 0.7) 35px, rgba(52, 139, 178, 0.7) 70px);
}

.o-card__suit {
  float: right;
  padding-right: .2rem;
  font-size: 2rem;
  line-height: 1;
}

BODY {
  perspective-origin: 100% 0%;
  perspective: 1500px;
}

BODY:hover .o-card {
  transform: rotateY(180deg);
}