<div class="outerBorder">
  <div class="container">
    <div class="ghostWrapper left">
      <div class="ghost">
        <div class="body">
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
        </div>
        <div class="eye left">
          <div></div>
          <div></div>
          <div></div>
        </div>
        <div class="eye right">
          <div></div>
          <div></div>
          <div></div>
        </div>
      </div>
    </div>
    
    <div class="pacmanWrapper">
      <div class="pacmanBody">
        <div class="pacman top"></div>
        <div class="pacman left"></div>
        <div class="pacman bottom"></div>
        <div class="eye"></div>
      </div>
    </div>

    <div class="ghostWrapper right">
      <div class="ghost">
        <div class="body">
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
        </div>
        <div class="eye left">
          <div></div>
          <div></div>
          <div></div>
        </div>
        <div class="eye right">
          <div></div>
          <div></div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
</div>

<a href="https://codemenatalie.com/blog" class="signature" target="_blank">Created by CodeMeNatalie</a>
$pacmanDurationTime: 5s;

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  font-size: 14px;
  background-color: black;

  .outerBorder,
  .container {
    border-top: 1px solid #1212bf;
    border-bottom: 1px solid #1212bf;
  }

  .outerBorder {
    padding: 2px 0;
  }

  .container {
    position: relative;
    width: 100px;
    height: 42px;
    overflow: hidden;

    .pacmanWrapper {
      position: absolute;
      top: 6px;
      left: 3px;
      animation: pacman $pacmanDurationTime linear infinite;

      .pacmanBody {
        position: relative;

        .pacman {
          position: absolute;
          width: 30px;
          height: 30px;
          border-radius: 50%;
          background-color: #ffff00;
          overflow: hidden;
        }

        .left {
          background: linear-gradient(
            to right,
            #f4d146 0%,
            #f4d146 49%,
            transparent 50%,
            transparent 100%
          );
          animation: body $pacmanDurationTime ease-in-out infinite;
        }

        .top {
          background: linear-gradient(
            to bottom,
            #f4d146 0%,
            #f4d146 51%,
            transparent 52%,
            transparent 100%
          );
          animation: top $pacmanDurationTime linear infinite;
        }

        .bottom {
          background: linear-gradient(
            to top,
            #f4d146 0%,
            #f4d146 49%,
            transparent 50%,
            transparent 100%
          );
          animation: bottom $pacmanDurationTime linear infinite;
        }

        .eye {
          position: absolute;
          width: 5px;
          height: 5px;
          left: 17px;
          top: 8px;
          background-color: #2c2e2e;
          border-radius: 50%;
          z-index: 2;
          animation: eye $pacmanDurationTime ease-in-out infinite;
        }
      }
    }

    .ghostWrapper {
      position: absolute;
      top: 6px;
      overflow: hidden;
      animation: ghostFloat 1s linear infinite,
        ghost $pacmanDurationTime linear infinite;

      &.left {
        left: -60px;

        .ghost {
          .body {
            div {
              background-color: #0df8e3;
            }
          }
          .eye {
            &.left {
              left: 6px;
            }

            &.right {
              right: 2px;
            }

            div {
              &:last-child {
                background-color: #2455fa;
                animation: leftEyeBalls $pacmanDurationTime linear infinite;
              }
            }
          }
        }
      }

      &.right {
        right: 5px;

        .ghost {
          .body {
            div {
              background-color: #ffa1cd;
            }
          }
          .eye {
            &.left {
              left: 2px;
            }

            &.right {
              right: 6px;
            }

            div {
              &:last-child {
                transform: translate3d(-4px, 0, 0);
                background-color: #2455fa;
                animation: rightEyeBalls $pacmanDurationTime linear infinite;
              }
            }
          }
        }
      }

      .ghost {
        width: 28px;
        position: relative;

        .body {
          div {
            float: left;
            width: 2px;

            &:nth-child(1),
            &:nth-child(14) {
              height: 16px;
              margin-top: 12px;
            }

            &:nth-child(2),
            &:nth-child(13) {
              height: 20px;
              margin-top: 6px;
            }

            &:nth-child(3),
            &:nth-child(12) {
              height: 20px;
              margin-top: 4px;
            }

            &:nth-child(4),
            &:nth-child(11) {
              height: 24px;
              margin-top: 2px;
            }

            &:nth-child(5),
            &:nth-child(10) {
              height: 26px;
              margin-top: 2px;
            }

            &:nth-child(6),
            &:nth-child(9) {
              height: 28px;
            }

            &:nth-child(7),
            &:nth-child(8) {
              height: 24px;
            }
          }
        }

        .eye {
          position: absolute;
          top: 6px;
          width: 8px;

          &.left {
            left: 6px;
          }

          &.right {
            right: 2px;
          }

          div {
            width: 2px;
            background-color: white;

            &:nth-child(1) {
              width: 4px;
              height: 10px;
              margin-left: 2px;
            }

            &:nth-child(2) {
              width: 8px;
              height: 6px;
              position: absolute;
              top: 2px;
            }

            &:nth-child(3) {
              width: 4px;
              height: 4px;
              position: absolute;
              top: 4px;
              right: 0;
            }
          }
        }
      }
    }
  }

  .signature {
    font-style: italic;
    font-size: 12px;
    color: #2455fa;
    padding-top: 15px;
    transition: all 0.3s ease-in-out;

    &:hover {
      color: #f4d146;
    }
  }
}

// pacman
@keyframes eye {
  0%,
  10%,
  20%,
  30%,
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  5%,
  15%,
  25% {
    transform: translate3d(-3px, -3px, 0);
    opacity: 1;
  }

  40% {
    transform: translate3d(0, 0, 0);
    opacity: 0;
  }

  44% {
    transform: translate3d(-10px, 0, 0);
    opacity: 0;
  }

  55%,
  65% {
    transform: translate3d(-10px, 0, 0);
    opacity: 1;
  }

  50%,
  60%,
  70% {
    transform: translate3d(-7px, -3px, 0);
    opacity: 1;
  }

  80% {
    transform: translate3d(-10px, 0, 0);
    opacity: 0;
  }

  94% {
    transform: translate3d(0, 0, 0);
    opacity: 0;
  }
}

@keyframes top {
  0%,
  10%,
  20%,
  29%,
  50%,
  60%,
  70%,
  99% {
    transform: rotate(20deg);
  }
  5%,
  15%,
  25%,
  45%,
  55%,
  65%,
  74% {
    transform: rotate(-30deg);
  }

  30%,
  44%,
  75%,
  99% {
    transform: rotate(0);
  }
}

@keyframes bottom {
  0%,
  10%,
  20%,
  29%,
  50%,
  60%,
  70%,
  100% {
    transform: rotate(-30deg);
  }

  5%,
  15%,
  25%,
  45%,
  55%,
  65%,
  74%,
  99% {
    transform: rotate(40deg);
  }

  30%,
  44%,
  75%,
  99% {
    transform: rotate(0);
  }
}

@keyframes body {
  0%,
  25%,
  75%,
  100% {
    transform: rotate(0deg);
  }

  55%,
  75% {
    transform: rotate(180deg);
  }
}

@keyframes pacman {
  0%,
  75%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  25%,
  50% {
    transform: translate3d(65px, 0, 0);
  }
}

// ghost
@keyframes ghost {
  0%,
  75%,
  100% {
    transform: translate3d(-5px, 0, 0);
  }

  25%,
  50% {
    transform: translate3d(65px, 0, 0);
  }
}

@keyframes ghostFloat {
  0%,
  100% {
    top: 9px;
  }
  50% {
    top: 3px;
  }
}

@keyframes rightEyeBalls {
  0%,
  1%,
  51%,
  100% {
    transform: translate3d(-4px, 0, 0);
  }

  2%,
  50% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes leftEyeBalls {
  0%,
  1%,
  51%,
  100% {
    transform: translate3d(-4px, 0, 0);
  }

  2%,
  50% {
    transform: translate3d(0, 0, 0);
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.