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

2.3 KiB

id title challengeType videoUrl
587d78a7367417b2b2512ae0 Use CSS Animation to Change the Hover State of a Button 0 https://scrimba.com/c/cg4vZAa

Description

You can use CSS @keyframes to change the color of a button in its hover state. Here's an example of changing the width of an image on hover:
<style>
  img:hover {
    animation-name: width;
    animation-duration: 500ms;
  }

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

<img src="https://bit.ly/smallgooglelogo" alt="Google's Logo" />

Instructions

Note that ms stands for milliseconds, where 1000ms is equal to 1s. Use CSS @keyframes to change the background-color of the button element so it becomes #4791d0 when a user hovers over it. The @keyframes rule should only have an entry for 100%.

Tests

tests:
  - text: The @keyframes rule should use the <code>animation-name</code> background-color.
    testString: 'assert(code.match(/@keyframes\s+?background-color\s*?{/g), ''The @keyframes rule should use the <code>animation-name</code> background-color.'');'
  - text: 'There should be one rule under <code>@keyframes</code> that changes the <code>background-color</code> to <code>#4791d0</code> at 100%.'
    testString: 'assert(code.match(/100%\s*?{\s*?background-color:\s*?#4791d0;\s*?}/gi), ''There should be one rule under <code>@keyframes</code> that changes the <code>background-color</code> to <code>#4791d0</code> at 100%.'');'

Challenge Seed

<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>

Solution

// solution required