Help us understand the problem. What is going on with this article?

CSS 図形が要素内を回るエフェクト

More than 3 years have passed since last update.

sampleGif.gif

要素にマウスが乗るとアニメーションさせる

html
<a href="#">Anchor</a>

css
a{
  position: relative;
  display: block;
  width: 100px;
  height: 100px;
  border: 1px solid #000;
  /* テキストを中央寄せ */
  text-align: center;
  line-height: 100px;
}

a:before,a:after{
  position: absolute;
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
}

a:before{
  top: 0;
  left: 0;
  background: linear-gradient(to left top,#55BEFC,#55FCBE);
}

a:after{
  bottom: 0;
  right: 0;
  background: linear-gradient(to left top,#FC55BE,#FCBE55);
}

a:hover:before{
  animation: anime_tl 5s linear infinite;
}

a:hover:after{
  animation: anime_br 5s linear infinite;
}

@keyframes anime_tl{
  0%{
    /* 左上 && 開始地点 */
    top: 0;
    left: 0;
  }

  25%{
    /* 右上 */
    top: 0;
    left: 100%;
    transform: translateX(-100%);
  }

  50%{
    /* 右下 */
    top: 100%;
    left: 100%;
    transform: translate(-100%,-100%);
  }

  75%{
    /* 左下 */
    top: 100%;
    left: 0;
    transform: translateY(-100%);
  }

  100%{
    /* 左上 && 終了地点*/
    top: 0;
    left: 0;
  }
}

@keyframes anime_br{
  0%{
    /* 右下 && 開始地点*/
    bottom: 0;
    right: 0;
  }

  25%{
    /* 左下 */
    bottom: 0;
    right: 100%;
    transform: translateX(100%);
  }

  50%{
    /* 左上 */
    bottom: 100%;
    right: 100%;
    transform: translate(100%,100%);
  }

  75%{
    /* 右上 */
    bottom: 100%;
    right: 0;
    transform: translateY(100%);
  }

  100%{
    /* 右下 && 終了地点*/
    bottom: 0;
    right: 0;
  }
}

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away