【发布时间】:2020-04-12 15:56:09
【问题描述】:
我有一个带有 div 叠加层的图像。 div 覆盖显示在悬停时。同样在悬停时,我想要一个动画效果。问题是,动画效果发生在图像和叠加层上,但我不希望动画效果发生在叠加层上。
此代码有效,但我无法阻止动画在叠加层上发生。什么 css 代码会让动画效果只发生在图像上?
所以在下面的代码中,css 正在容器图像上工作,但它也在额外层上发生。如何使其仅适用于容器映像?
html
<special class=“container”>
<a href=“#" class=“container-link”>
<img src=“image.jpg" class=“container-image”>
<div class=“extra-layer”></div>
</a>
</special>
css
#container {
position: relative;
}
.container ::before {
position: absolute;
-webkit-transform: translate(-60%, -60%);
transform: translate(-60%, -60%);
opacity: .5;
}
.container :hover::before {
-webkit-animation: circle .55s;
animation: circle .55s;
}
【问题讨论】:
-
去掉 :hover 和 :before 之前的空格
-
符号
“也很可能会遇到伤害世界,请使用标准括号",即<special class="container"> -
您好 Paulie_D,谢谢,但这没有用。然后什么都不会发生。
-
您好 EGC,它们在真实代码中是正确的,当我将代码放在此页面上时,我想这只是一个剪切和粘贴问题。
-
我们需要更清楚地解释您想要发生的事情 + 并且需要一个最小可重现示例stackoverflow.com/help/minimal-reproducible-example / - 如果我们要提供帮助。这是一个开始:jsfiddle.net/sheriffderek/48u02ebf