Parallax Card

16 Апреля 2021 02:12 (Редактировано: 16 Апреля 2021 02:14)

HTML

<div class="pseudo-parallax-card-container flex flex-row">
  <div class="mock top left"></div>
  <div class="mock top right"></div>
  <div class="mock bottom left"></div>
  <div class="mock bottom right"></div>
  
  <div class="content-container flex">
    <div class="controls-container flex flex-row">
      <span class="control"></span>
      <span class="control"></span>
      <span class="control"></span>
    </div>
    <div class="message-container">
      <div class="message message-one"></div>
      <div class="message message-two"></div>
      <div class="message message-three"></div>
      <div class="instructions">
        <h2 class="name">Parallax Card</h2>
      </div>
    </div>
  </div>
</div>

CSS

:root {
  --angleX: 0deg;
  --angleY: 0deg;
}
body {
  height: 100vh;
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  background-color: #adc0ca;
  transform-style: preserve-3d;
  transform: perspective(600px);
  font-family: "Open Sans", sans-serif;
}
.flex {
  display: flex;
}
.flex.flex-row {
  flex-flow: row wrap;
}
.pseudo-parallax-card-container {
  width: 300px;
  height: 350px;
}
.mock {
  width: 50%;
  height: 50%;
  z-index: 2;
}
.mock.left.top:hover ~ .content-container {
  --angleX: 8deg;
  --angleY: -25deg;
}
.mock.left.bottom:hover ~ .content-container {
  --angleX: -8deg;
  --angleY: -25deg;
}
.mock.right.top:hover ~ .content-container {
  --angleX: 8deg;
  --angleY: 25deg;
}
.mock.right.bottom:hover ~ .content-container {
  --angleX: -8deg;
  --angleY: 25deg;
}
.content-container {
  position: absolute;
  justify-content: center;
  align-items: center;
  width: 300px;
  height: 350px;
  text-align: center;
  background-color: #2e4362;
  border-radius: 10px;
  color: black;
  user-select: none;
  transition: box-shadow 0.5s ease, transform 0.65s ease;
  will-change: transform;
  box-shadow: -20px 10px 20px rgba(0, 0, 0, 0.4);
  transform: translatey(0) rotatex(var(--angleX, 0)) rotatey(var(--angleY, 0)) translatez(-10px);
  filter: brightness(110%);
}
.controls-container {
  position: absolute;
  top: 5%;
  left: 75%;
  width: 50px;
  height: 20px;
  justify-content: space-between;
}
.controls-container .control {
  width: 10px;
  height: 10px;
  border-radius: 100%;
  background-color: #2e4362;
  box-shadow: -2px 2px 1px black, -0.5px 1px 0px #f0f0f0 inset;
}
.message-container .message {
  position: absolute;
  top: 35%;
  left: -20%;
  width: 180px;
  height: 40px;
  z-index: 200;
  border-radius: 20px;
  box-shadow: -20px 10px 10px rgba(0, 0, 0, 0.2), -1px -1px 0px #a0a0a0 inset;
}
.message-container .message-one {
  background: #528acf;
}
.message-container .message-two {
  top: 55%;
  left: 60%;
  background: #ffb6cd;
}
.message-container .message-three {
  top: 75%;
  left: 60%;
  background: #97fac9;
}
.message-container .instructions {
  position: absolute;
  top: 10%;
  width: 100%;
  left: 0%;
}
.name {
  color: #adc0ca;
}

Результат