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

1.8 KiB
Raw Blame History

id challengeType videoUrl forumTopicId title
587d78a7367417b2b2512ae0 0 https://scrimba.com/c/cg4vZAa 301073 使用CSS动画更改按钮的悬停状态

Description

你可以在按钮悬停时使用 @keyframes 改变按钮的颜色。 下面是在图片悬停时改变图片宽度的例子:
<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

注意 ms 代表毫秒1000ms 等于 1s。 使用 @keyframes 来改变 button 元素的 background-color,使其当悬停时变成 #4791d0@keyframes 规则应该只有一个 100% 条目。

Tests

tests:
  - text: '<code>@keyframes</code> 规则的 <code>animation-name</code> 应该是 background-color。'
    testString: assert(code.match(/@keyframes\s+?background-color\s*?{/g));
  - text: '在 <code>@keyframes</code> 的 <code>100%</code> 条目里应该把 <code>background-color</code> 改成 <code>#4791d0</code>。'
    testString: assert(code.match(/100%\s*?{\s*?background-color:\s*?#4791d0;\s*?}/gi));

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>注册</button>

Solution

// solution required