为什么transition有没有用呢,没有加display?

代码运行网站:
https://www.runoob.com/try/try.php?filename=tryhtml5_video_bear

全部代码
<!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>
        .father{
            width: 200px;
            height: 280px;
            position: relative;
        }
        .father:hover p{
            animation: p_change 0.5s forwards;
        }
        a{
            width: 100%;
            height: 100%;
            background-color: red;
            display: inline-block;
        }
        p{
            margin: 0px;
            width: 10%;
            height: 10%;
            background-color: aqua;
            opacity: 0;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            transition: all 0.5s;
        }
        @keyframes p_change {
            100%{
                width: 100%;
                height: 100%;
                opacity: 1;
            }
}
    </style>
</head>
<body>
    <div class="father">
        <a>
        </a>
        <p></p>
    </div>
</body>
</html>

img

google和firfox正常

1、注意浏览器,兼容
transform:
-webkit-transform:
-moz-transform:
-o-transform:
-ms-transform:
2、有定位的最好配上z-index

总要给p标签添加个触发条件吧,transition是过渡属性,要变化才能生效;

/* .father:hover p {
  animation: p_change 0.5s forwards;
} */

p:hover {
      width: 100%;
      height: 100%;
      opacity: 1;
}

你在hover里面覆盖了


.father:hover p{
            animation: p_change 0.5s forwards;
        }