LoginSignup
33

More than 5 years have passed since last update.

CSSでテキストを踊らせる。

Posted at

sample.gif


<div class="text">
  <span>C</span>
  <span>S</span>
  <span>S</span>
  <span></span>
</div>

.text{
  font-size: 3em;
  color: white;
}

.text span{ 
  display: inline-block;
  animation: textAnim 1s linear infinite alternate;
}

@keyframes textAnim{
  from{
    transform-origin: left bottom;
    transform: rotate(-15deg);
  }
  to{
    transform-origin: right bottom;
    transform: rotate(+15deg);
  }
}

ポイントは アニメーションで transform-originを変化させること。
これによって、踊っているように見える。

spandisplay: inline-blockと指定している。
これは デフォルトのinlineだと transformが効かないため。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33