JSFiddle - React, Tailwind, and code Playground

by Filipp Dernovoy

HTML

<div class="div marquee">
  <div class="marquee__control"></div>
  <span class="marquee__content">Наш бегущий текст. Текст, который будет двигаться справа налево и обратно.</span>
</div>

<div class="div marquee">
  <div class="marquee__control"></div>
  <span class="marquee__content">Короткий текст.</span>
</div>

CSS

.marquee {
  width: 100px;
  padding: 7px;
  font: 12px Arial;
  background: #ddd;
  border-radius: 3px;
  margin-bottom: 5px;
  height: 1.2em;
  overflow: hidden;
  position: relative;
}

.marquee::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  box-shadow: inset 5px 0 5px #ddd, inset -5px 0 5px #ddd;
  z-index: 2;
}

.marquee::after {
  content: '';
  background: transparent;
  display: inline-block;
  top: -7px;
  height: 200%;
  width: 200%;
  margin-left: -100%;
  margin-right: -100%;
  position: relative;
  z-index: 2;
}

.marquee__content {
  display: inline-block;
  white-space: nowrap;
  animation: marquee 5s infinite ease-in-out alternate;
  animation-play-state: paused;
  position: relative;
  height: 3em;
  vertical-align: top;
}

.marquee__control {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  z-index: 2;
}

.marquee__control:hover + .marquee__content {
  animation-play-state: running;
}

@keyframes marquee {
  0% {
    transform: translate(0, 0);
    left: 0;
  }

  100% {
    transform: translate(calc(-100%), 0);
    left: 100%;
  }
}