【发布时间】:2016-05-26 13:51:23
【问题描述】:
我创建了 2 个相同大小的 div。第一个 div 的 z-index=1 并且颜色为红色。第二个 div 的 z-index=0 并且颜色为黄色。我希望在将鼠标悬停在 div 上时,黄色框(最初位于下方)的 z-index 应在 2 秒后变为 2(以便它出现)。但我不明白为什么代码不起作用。
#animate1,
#animate2 {
position: absolute;
top: 0;
left: 0;
width: 50px;
height: 50px;
}
#animate1 {
background-color: red;
z-index: 1;
}
#animate2 {
background-color: yellow;
z-index: 0;
transition: z-index 0 linear 2s;
}
#all:hover #animate2 {
z-index: 2;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="all">
<div id="animate1">
</div>
<div id="animate2">
</div>
</div>
</body>
</html>
【问题讨论】:
-
你所期望的没有做什么?查看codepen.io/chriscoyier/pen/gboJf