老师请帮忙看一下这样写对吗?有没有更简便的方法呢?
来源:2-14 编程练习
铁蛋金刚侠
2020-11-22 13:05:22
# 具体遇到的问题
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#myTest{
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
background-color: #f43838;
margin: auto;
margin-top: 100px;
color: #FFF;
cursor: pointer;
font-size: 20px;
font-weight: bold;
/*添加代码*/
animation:changeback 1s linear 0s forwards;
}
#myTest:hover{
/*添加代码*/
animation:change 1s linear 0s forwards;
}
@keyframes change{
from {
width: 100px;
height: 100px;
background-color: #f43838;
line-height: 100px;
}
to {
font-size:40px;
width: 200px;
height: 200px;
background-color:green;
line-height: 200px;
border-radius: 50%;
}
}
@keyframes changeback{
from {
font-size:40px;
width: 200px;
height: 200px;
background-color:green;
line-height: 200px;
border-radius: 50%;
}
to {
width: 100px;
height: 100px;
background-color: #f43838;
line-height: 100px;
}
}
</style>
</head>
<body>
<div id="myTest"> duang! </div>
</body>
</html>
在这里输入代码,可通过选择【代码语言】突出显示
1回答
同学你好,这样写,页面打开时,元素就会做动画,与练习要求不符。建议使用transition过渡实现效果,如下:
这样就可以实现鼠标移入元素时,元素变形,鼠标移出时,元素还原。
祝学习愉快!
相似问题