使用过渡时,您必须定义开始和结束。代替背景无,使用 rgba(255,255,255,0); 所以开头和结尾说的是同一种语言。
CSS 不理解诸如“背景颜色”->“无”之类的过渡。此外,在这种情况下,您可能希望使用透明,因为“none”对于背景颜色来说不是有效的 CSS。
我还认为您的 CSS 的某些部分可能不兼容。如果你删除了规模的东西,事情就会按照他们应该的方式行事。真可惜。看看我的第二个小提琴,这似乎工作,所以也许你只需要写一些更干净的代码或什么?我使用了图形而不是图像,但它的作用应该相同。希望这可以帮助!
这是您更新的小提琴,然后是我的小提琴。
<figure>
<figcaption>without scale</figcaption>
</figure>
<figure class="scale">
<figcaption>with scale</figcaption>
</figure>
--
.trans, figure, figcaption {
-webkit-transition: all .5s linear;
-moz-transition: all .5s linear;
-o-transition: all .5s linear;
transition: all .5s linear;
}
figure {
position: relative;
width: 20em;
height: 10em;
background-color: rgba(255,0,104,1);
}
figure:hover {
background-color: rgba(255,0,104,.2);
}
figcaption {
position: absolute;
width: 100%;
bottom: 0; left: 0;
padding: 2em 1em;
background-color: rgba(255,255,255,.8);
}
figure:hover figcaption {
bottom: 20px;
background-color: rgba(255,255,255,.0);
}
.scale:hover {
-webkit-transform: scale(1.1, 1.1);
-moz-transform: scale(1.1, 1.1);
-ms-transform: scale(1.1, 1.1);
-o-transform: scale(1.1, 1.1);
transform: scale(1.1, 1.1);
}