koskywalker
11/4/2019 - 7:27 AM

rainbow button

button colorful

button colorful

カラフルにアニメーションするボタン.

A Pen by Kosuke Muraka on CodePen.

License.

<div class="button-colorful">
  <div class="button-colorful__inner">
    <a href="#" class="button-colorful__link"><span class="button-colorful__link-text">チケット購入はこちら</span></a>
  </div>
</div>
<script src="https://kit.fontawesome.com/5aa3776b36.js" crossorigin="anonymous"></script>
.button-colorful {
  animation: background_colorful 10s infinite;
  font-family: -apple-system, "Segoe UI", 游ゴシック体, "Yu Gothic", YuGothic, "ヒラギノ角ゴ Pro", "ヒラギノ角ゴ W3", "Hiragino Kaku Gothic Pro", メイリオ, meiryo, sans-serif;
  padding: 2px;
  width: 50%;

  &__inner {
    position: relative;
    overflow: hidden;

    &::before {
      bottom: 0px;
      left: 100%;
      width: 100%;
      height: 1px;
      animation: line_loop_left 2s linear 0s infinite;
    }

    &::after {
      bottom: 100%;
      right: 0;
      width: 1px;
      height: 100%;
      animation: line_loop_bottom 2s linear 1s infinite;
    }
  }

  &__link {
    animation: background_colorful 10s infinite;
    display: inline-block;
    text-align: center;
    font-size: 138.5%;
    color: #fff;
    text-decoration: none;
    height: 100%;
    width: 100%;
    padding: 8px;

    &:hover {
      opacity: 0.8;
      transition: 0.3s;
    }

    &::before {
      top: 0;
      right: 100%;
      width: 100%;
      height: 1px;
      animation: line_loop_right 2s linear 0s infinite;
    }

    &::after {
      top: 100%;
      left: 0;
      width: 1px;
      height: 100%;
      animation: line_loop_top 2s linear 1s infinite;
    }
  }

  &__link-text::after {
    display: inline-block;
    font-family: 'FontAwesome';
    content: "\f0a9";
    margin-left: 1em;
    font-weight: normal;
    animation: opacity_loop 3s infinite;
  }

  &__inner::before,
  &__inner::after,
  &__link::before,
  &__link::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.63);
  }
}

@keyframes background_colorful {
  0% {
    background: #009337;
    box-shadow: 0 5px 0 #00561f, 0 10px 0 rgba(0, 0, 0, .2);
  }

  25% {
    background: #f1961b;
    box-shadow: 0 5px 0 #9d6111, 0 10px 0 rgba(0, 0, 0, .2);
  }

  50% {
    background: #e40038;
    box-shadow: 0 5px 0 #8c0023, 0 10px 0 rgba(0, 0, 0, .2);
  }

  75% {
    background: #00a5da;
    box-shadow: 0 5px 0 #005876, 0 10px 0 rgba(0, 0, 0, .2);
  }

  100% {
    background: #009337;
    box-shadow: 0 5px 0 #00561f, 0 10px 0 rgba(0, 0, 0, .2);
  }
}

@keyframes opacity_loop {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }

  100% {
    opacity: 1;
  }
}

@keyframes line_loop_top {
  0% {
    top: -100%;
  }

  100% {
    top: 100%;
  }
}

@keyframes line_loop_bottom {
  0% {
    bottom: -100%;
  }

  100% {
    bottom: 100%;
  }
}

@keyframes line_loop_right {
  0% {
    right: -100%;
  }

  100% {
    right: 100%;
  }
}

@keyframes line_loop_left {
  0% {
    left: -100%;
  }

  100% {
    left: 100%;
  }
}