freeCodeCamp/curriculum/challenges/japanese/01-responsive-web-design/applied-visual-design/use-css-animation-to-change...

2.2 KiB

id title challengeType videoUrl forumTopicId dashedName
587d78a7367417b2b2512ae0 CSS アニメーションを使用してボタンのホバー状態を変更する 0 https://scrimba.com/c/cg4vZAa 301073 use-css-animation-to-change-the-hover-state-of-a-button

--description--

CSS の @keyframes を使ってホバー状態の時にボタンの色を変えることができます。

下記は画像の幅をホバー時に変更する例です:

<style>
  img {
    width: 30px;
  }
  img:hover {
    animation-name: width;
    animation-duration: 500ms;
  }

  @keyframes width {
    100% {
      width: 40px;
    }
  }
</style>

<img src="https://cdn.freecodecamp.org/curriculum/applied-visual-design/google-logo.png" alt="Google's Logo" />

--instructions--

ms はミリ秒を表すので、1000 ms で 1 秒となることに注意してください。

CSS の @keyframes を使用して button 要素の background-color を変更し、ユーザーがボタンにホバーすると #4791d0 になるようにしてください。 @keyframes ルールには 100% の項目のみ記載されているようにしてください。

--hints--

@keyframes ルールは background-color という animation-name を使う必要があります。

assert(code.match(/@keyframes\s+?background-color\s*?{/g));

@keyframes には、100% 時点で background-color#4791d0 に変更するルール 1 つだけがあるようにしてください。

assert(code.match(/100%\s*?{\s*?background-color:\s*?#4791d0;\s*?}/gi));

--seed--

--seed-contents--

<style>
  button {
    border-radius: 5px;
    color: white;
    background-color: #0F5897;
    padding: 5px 10px 8px 10px;
  }

  button:hover {
    animation-name: background-color;
    animation-duration: 500ms;
  }


</style>

<button>Register</button>

--solutions--

<style>
  button {
    border-radius: 5px;
    color: white;
    background-color: #0F5897;
    padding: 5px 10px 8px 10px;
  }

  button:hover {
    animation-name: background-color;
    animation-duration: 500ms;
  }

  @keyframes background-color {
    100% {
      background-color: #4791d0;
    }
  }
</style>
<button>Register</button>