老师请帮忙看一下这样写对吗?有没有更简便的方法呢?

来源:2-14 编程练习

铁蛋金刚侠

2020-11-22 13:05:22

# 具体遇到的问题

# 报错信息的截图

# 相关课程内容截图

# 尝试过的解决思路和结果

# 粘贴全部相关代码,切记添加代码注释(请勿截图)

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Document</title>

    <style>

        #myTest{

            width100px;

            height100px;

            text-aligncenter;

            line-height100px;

            background-color#f43838;

            marginauto;

            margin-top100px;

            color#FFF;

            cursorpointer;

            font-size20px;

            font-weightbold;

        /*添加代码*/

        animation:changeback 1s linear 0s forwards;

            



        }

        #myTest:hover{

            /*添加代码*/

            animation:change 1s linear 0s forwards;


        }


        @keyframes change{

            from {

                width100px;

                height100px;

                background-color#f43838;

                line-height100px;

                


            }

            to {

                font-size:40px;

                width200px;

                height200px;

                background-color:green;

                line-height200px;

                border-radius50%;

                

            }

        }



        @keyframes changeback{

            from {


                

                font-size:40px;

                width200px;

                height200px;

                background-color:green;

                line-height200px;

                border-radius50%;


            }

            to {

                width100px;

                height100px;

                background-color#f43838;

                line-height100px;

                

            }

        }



    </style>

</head>

<body>

    <div id="myTest">  duang! </div>

</body>

</html>


在这里输入代码,可通过选择【代码语言】突出显示

写回答

1回答

好帮手慕久久

2020-11-22

同学你好,这样写,页面打开时,元素就会做动画,与练习要求不符。建议使用transition过渡实现效果,如下:

http://img.mukewang.com/climg/5fb9fdb909f9dd5707760463.jpg

http://img.mukewang.com/climg/5fb9fdd7093ff7d008180197.jpg
这样就可以实现鼠标移入元素时,元素变形,鼠标移出时,元素还原。

祝学习愉快!

0

0 学习 · 15276 问题

查看课程