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

练习题目:

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

练习代码:

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

效果如下:

问题:

因为持续时间只设置了0.5s,所以动画结束,按钮的颜色就变暗了。

如果希望鼠标放在上面,按钮一直保持高亮

通过如下设置,可以改进:

That's great, but it doesn't work right yet.

Notice how the animation resets after 500ms has passed, causing the button to revert back to the original color.

You want the button to stay highlighted.

This can be done by setting the animation-fill-mode property to forwards. The animation-fill-mode specifies the style applied to an element when the animation has finished. You can set it like so:

animation-fill-mode: forwards;

所以添加后代码:

 <style>
button {
border-radius: 5px;
color: white;
background-color: #0F5897;
padding: 5px 10px 8px 10px;
}
button:hover {
animation-name: background-color;
animation-duration: 500ms;
/* add your code below this line */
animation-fill-mode: forwards;
/* add your code above this line */
}
@keyframes background-color {
100% {
background-color: #4791d0;
}
}
</style>
<button>Register</button>

FCC---Use CSS Animation to Change the Hover State of a Button---鼠标移过,背景色变色,用0.5s的动画制作的更多相关文章

  1. CSS Animation triggers text rendering change in Safari

    薄荷新首页上周五内测,花哥反馈在 MacBook Safari 浏览器下 鼠标移动到第一个商品的时候后面几个商品的文字会加粗.这是什么鬼??? 待我回到家打开笔记本,鼠标蹭蹭蹭的发现问题远不止如此: ...

  2. No.6 - 利用 CSS animation 制作一个炫酷的 Slider

    *{ margin:; padding:; } div{ margin: auto; width: 800px; height: 681px; position: relative; overflow ...

  3. 百度前端技术学院2018笔记 之 利用 CSS animation 制作一个炫酷的 Slider

    前言 题目地址 利用 CSS animation 制作一个炫酷的 Slider 思路整理 首先页面包含三种东西 一个是type为radio的input其实就是单选框 二是每个单选框对应的label 三 ...

  4. CSS animation & CSS animation 101

    CSS animation 101 如何为 Web 添加动画效果. https://github.com/cssanimation/css-animation-101 https://github.c ...

  5. CSS Animation

    div { /* Chrome, Safari, Opera 等使用webkit引擎的浏览器*/ -webkit-animation-name: myfirst; /*规定 @keyframes 动画 ...

  6. CSS魔法堂:更丰富的前端动效by CSS Animation

    前言  在<CSS魔法堂:Transition就这么好玩>中我们了解到对于简单的补间动画,我们可以通过transition实现.那到底多简单的动画适合用transtion来实现呢?答案就是 ...

  7. CSS中的onmouseover和hover有什么区别

    它们一样是因为:都是鼠标落上去的时候触发的.它们不一样是因为:onmousemove是javascript里面的,他可以触发js命令,但是hover做不到,hover只是css样式的类,只能定义样式. ...

  8. [CSS3] Make a One-time CSS Animation that Does Not Revert to its Original Style

    We'll add animation to patio11bot using CSS keyframes. When defining a CSS animation, you can add it ...

  9. 超链接标签的CSS伪类link,visited,hover,active

    CSS伪类,是一种特殊的类,它针对到CSS选择器起作用,使选中的标签或元素产生特定的效果. CSS伪类的语法就是: 选择器 : 伪类名 { 属性 : 属性值 } 用的最多的伪类就是超链接a的伪类,有: ...

随机推荐

  1. vue事件监听机制

    vue事件是同步的.如果绑定了事件(组件标签上绑定事件) 组件的事件触发 组件调用时绑定事件 之后监听事件: $emit 抛出后活等着 $on ,如果监听到了则阻塞执行: 如果为监听到或者未绑定,则会 ...

  2. 什么是EAC模型

    在20世纪70年代末,一个心理学学生理查德•班德勒和一个语言学学生约翰•格林德提出了一个EAC模型,即眼睛解读线索.这个模型对不同的感官和思维方式之间进行一些有效的研究, 对于大部分的人来说,左边往往 ...

  3. [Spring cloud 一步步实现广告系统] 13. 索引服务编码实现

    上一节我们分析了广告索引的维护有2种,全量索引加载和增量索引维护.因为广告检索是广告系统中最为重要的环节,大家一定要认真理解我们索引设计的思路,接下来我们来编码实现索引维护功能. 我们来定义一个接口, ...

  4. 基于asp.net(C#)MVC+前端bootstrap+ztree+lodash+jquery技术-Angel工作室通用权限管理

    一.Angel工作室简单通用权限系统简介 AngelRM(Asp.net MVC Web api)是基于asp.net(C#)MVC+前端bootstrap+ztree+lodash+jquery技术 ...

  5. JAVAEE学期总结

         声明:除第一张思维导图为博主所制作,其他思维导图皆来自网络,若侵权,望告知,必删除.                                                      ...

  6. zabbix监控服务

    1.模板的重要 ​ 1.手动添加监控比较麻烦,监控项 -> 图形 -> 触发器. 问题: 1.例如: 100台服务器需要检查81端口 2.例如: 100台服务器81改成82 解决: 使用模 ...

  7. Java - IO System类支持和缓冲流

    System类的支持和缓冲流 System类对IO的支持 在System类中,为了支持IO操作提供了三个常量: 错误输出: public static final PrintStream err; 输 ...

  8. Flask报如下错误:SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.

    在同一个项目中由于flask_sqlalchemy版本不同,有时会报如下错误 错误信息如下: flask_sqlalchemy\__init__.py:: UserWarning: SQLALCHEM ...

  9. 使用scale等比例缩放图片

    功能需求: 在下拉框中选择你所需要缩放的比例, 选择好了之后,图片会按照你选择的比例进行缩放 1==>如何获取select中option选中的值 在select添加事件change 和双向绑定v ...

  10. day88_11_8,事务的隔离级别celery定时订单与项目整合。

    一.事务的隔离级别. mysql的默认数据库级别是可重复读,一般的应用使用的是读已提交 http://www.zsythink.net/archives/1233/ 1. Read UnCommitt ...