相当简单的HTML结构:.interview
有一个.overlay
的孩子display:none
。当徘徊.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 };
}
为了在这里工作,我必须在哪里进行过渡?
答案 0 :(得分:0)
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>
&#13;