FCC---Use CSS Animation to Change the Hover State of a Button---鼠标移过,背景色变色,用0.5s的动画制作
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的动画制作的更多相关文章
- CSS Animation triggers text rendering change in Safari
薄荷新首页上周五内测,花哥反馈在 MacBook Safari 浏览器下 鼠标移动到第一个商品的时候后面几个商品的文字会加粗.这是什么鬼??? 待我回到家打开笔记本,鼠标蹭蹭蹭的发现问题远不止如此: ...
- No.6 - 利用 CSS animation 制作一个炫酷的 Slider
*{ margin:; padding:; } div{ margin: auto; width: 800px; height: 681px; position: relative; overflow ...
- 百度前端技术学院2018笔记 之 利用 CSS animation 制作一个炫酷的 Slider
前言 题目地址 利用 CSS animation 制作一个炫酷的 Slider 思路整理 首先页面包含三种东西 一个是type为radio的input其实就是单选框 二是每个单选框对应的label 三 ...
- CSS animation & CSS animation 101
CSS animation 101 如何为 Web 添加动画效果. https://github.com/cssanimation/css-animation-101 https://github.c ...
- CSS Animation
div { /* Chrome, Safari, Opera 等使用webkit引擎的浏览器*/ -webkit-animation-name: myfirst; /*规定 @keyframes 动画 ...
- CSS魔法堂:更丰富的前端动效by CSS Animation
前言 在<CSS魔法堂:Transition就这么好玩>中我们了解到对于简单的补间动画,我们可以通过transition实现.那到底多简单的动画适合用transtion来实现呢?答案就是 ...
- CSS中的onmouseover和hover有什么区别
它们一样是因为:都是鼠标落上去的时候触发的.它们不一样是因为:onmousemove是javascript里面的,他可以触发js命令,但是hover做不到,hover只是css样式的类,只能定义样式. ...
- [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 ...
- 超链接标签的CSS伪类link,visited,hover,active
CSS伪类,是一种特殊的类,它针对到CSS选择器起作用,使选中的标签或元素产生特定的效果. CSS伪类的语法就是: 选择器 : 伪类名 { 属性 : 属性值 } 用的最多的伪类就是超链接a的伪类,有: ...
随机推荐
- RocketMQ(一):推拉消费模型客户端实践
消息中间件是为解耦生产者和消费者的目的,三大服务点:解耦.异步.削峰. 现在的的互联网系统中,mq已经必备基础设施了,我们已明显感觉它的必要性与强大.然而,它的本质是啥?存储转发系统罢了! MQ有很多 ...
- 结对编程项目复盘:带UI的小初高数学学习软件
实现个人项目时,由于我当时的Java GUI编程基础还比较薄弱,所以我选择通过命令行实现,并将编程开发的重点放到了算法效率上去.没能设计出用户体验更佳的UI成为了我在个人项目阶段最大的遗憾. 在这次结 ...
- JS基础语法---String对象
String---->是一个对象 字符串可以看成是字符组成的数组, 但是js中没有字符类型 字符是一个一个的, 在别的语言中字符用一对单引号括起来 在js中字符串可以使用单引号也可以使用双引号 ...
- Windows应急日志常用的几个事件ID
Windows应急日志常用的几个事件ID点击站内没有搜索到,可能搜索姿势不对,发一下吧,应急时可能会用到,根据日志时间点判断入侵 日志路径:C:\Windows\System32\winevt\Log ...
- Xcode报错:could not attach to pid:"1764"
这种错误不是什么问题,按照参考链接操作即可,亲测有效: https://www.cnblogs.com/luorende/p/6295945.html 在运行项目时出现了如下错误 (基本上重新启动项目 ...
- RAC ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
重启RAC时发现32004,后来才发现DG已经不存在了standby_archive_dest还在生效中,而background_dump_dest和user_dump_dest并没在pfile中出现 ...
- Linux iotop工具简介
iotop的简介: iotop是一款开源.免费的用来监控磁盘I/O使用状况的类似top命令的工具,iotop可以监控进程的I/O信息.它是Python语言编写的,与iostat工具比较,iostat是 ...
- 远程访问阿里云服务器jupyter
官网链接 一.pip安装jupyter安装Anaconda的话,会自动按照jupyter,就不需要再使用pip安装了 pip3 install jupyter 二.生成jupyter notebook ...
- mssql sqlserver 添加表注释和添加列注释的方法分享
转自: http://www.maomao365.com/?p=8919 摘要: 下文讲述使用sql脚本对数据表或数据列添加注释(备注说明)的方法分享,如下所示: 实验环境:sql server 2 ...
- Linux Thermal Framework分析及实施
关键词:Zone.Cooling.Governor.Step Wise.Fair Share.trip等等. Linux Thermal的目的是控制系统运行过程中采样点温度,避免温度过高造成器件损坏, ...