html - 有没有办法让这个按钮动画?
问题描述
我最近正在尝试使用 HTML/CSS 编写一个动画按钮(它是一个特定的装饰链接),对我需要避免的所有事情提出异议,我还有一个问题要成功:使以下编码的按钮像变换一样动画悬停和活动的属性。
.button{
display:inline;
text-decoration:none;
font-size:50px;
font-family:monospace;
color:blue;
margin:15px;
padding:5px 10px;
background-color:lightgreen;
box-shadow:5px 10px grey;
border-radius:15px;
position:relative;
}
.button:hover{
background-color:yellow;
color:darkgreen;
top:-5px;
left:-3px;
box-shadow:8px 15px grey;
}
.button:active{
top:+3px;
left:+5px;
box-shadow:5px 5px grey;
}
<div class="button">Button</div>
解决方案
您需要使用transition
设置哪些属性应该设置动画(即all
),动画应该持续多长时间(我通常会选择0.25s
悬停效果)和计时功能。
您还需要:hover
在默认块中定义您使用的所有属性(即top
,left
)
.button {
transition: all 0.25s linear;
font-size: 50px;
font-family: monospace;
color: blue;
margin: 15px;
padding: 5px 10px;
background-color: lightgreen;
box-shadow: 5px 10px grey;
border-radius: 15px;
position: relative;
top: 0px;
left: 0px;
}
.button:hover {
background-color: yellow;
color: darkgreen;
top: -5px;
left: -3px;
box-shadow: 8px 15px grey;
}
.button:active {
top: 3px;
left: 5px;
box-shadow: 5px 5px grey;
}
<button class="button">Hello</button>
推荐阅读
- mysql - 优化Mysql中的Union查询
- java - 使用改造 2 在 android 中显示 RecyclerView 中的数据时出错
- amazon-web-services - AWS Cloud Formation 模板失败,并指定了无效的映射表达式参数
- influxdb - InfluxDB:对具有相同时间戳的行进行分组
- c - 函数地址错误
- ios - UITableView 由于在滚动 tableview 的同时重新加载数据而崩溃
- asp.net-mvc - niginx 反向代理背后的 Oauth 服务器应用程序
- hyperlink - Microsoft Flow 超链接在 Outlook 客户端中不起作用
- android - 如何在network-security-config.xml文件Android中动态添加includeSubdomains
- xpages - 如何将富文本附件从一个文档传输到另一个文档