麻烦老师检查代码,谢谢

来源:2-9 自由编程

叫我丽红

2021-04-25 15:19:44

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

        *{

            margin0;

            padding0;

        }


        .box{

            width200px;

            height200px;

            overflowhidden;

            positionrelative;


        }


        .box img{

            width200px;

            height200px;

        }


        .box p{

            positionabsolute;

            width200px;

            height20px;

            line-height20px;

            background-color:rgba(0,0,0,.5);

            colorwhite;

            text-aligncenter;

            opacity0;

            bottom:-30px;

            transitionbottom 1s linear 0s;

            


        }


        .box:hover p{

            opacity1;

            bottom:0px;


        }




    </style>

</head>

<body>

    <div class="box">

        <img src="images/cat.jpg" alt="">

        <p>这是一只小猫</p>

    </div>

</body>

</html>


写回答

1回答

好帮手慕星星

2021-04-25

同学你好,测试代码移入的时候有过渡效果,但是移出的时候没有。

这是因为p改变了opacity,而过渡中只写了bottom属性,导致移出的时候突然改变。建议去掉opacity属性的改变,如下:

http://img.mukewang.com/climg/60852966093d8b1704990398.jpg

祝学习愉快!

0

0 学习 · 15276 问题

查看课程