CSS:带有子元素转换的动画悬停

时间:2014-12-17 17:37:18

标签: html5 css3 hover css-transitions

我猜是简单的问题,但似乎无法找到解决方案...

相当简单的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 };
}

为了在这里工作,我必须在哪里进行过渡?

1 个答案:

答案 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;
&#13;
&#13;