我猜是简单的问题,但似乎找不到解决方案......
相当简单的HTML结构:.interview
有一个display:none
的子.overlay
。当悬停在孩子身上时.interview
我想淡出。但是不起作用。
.interview {
background:red;
position:relative;
height:710px;
/*Transition*/
transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-webkit-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-moz-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-o-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-ms-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
}
.interview .overlay {
position:absolute;
background:rgba(0, 0, 0, 0.6);
height:100%;
width:100%;
top:0;
left:0;
display:none;
}
.interview:hover {
.overlay { display:block };
}
为了在这里工作,我必须把过渡放在哪里?
display:none;从页面中删除一个块,就好像它从未存在过一样。
改用opacity
显示属性不适用于过渡
.interview {
background: red;
position: relative;
height: 710px;
/*Transition*/
transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-webkit-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-moz-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-o-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
-ms-transition: all .5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
}
.interview .overlay {
position: absolute;
background: rgba(0, 0, 0, 0.6);
height: 100%;
width: 100%;
top: 0;
left: 0;
opacity: 0;
transition: 1s linear;
}
.interview:hover .overlay {
opacity: 1;
}
<div class="interview">
<div class="overlay"></div>
</div>