【发布时间】:2021-11-23 09:10:00
【问题描述】:
我有这个来自互联网的心形动画,div 使用::before 和::after 制作了一个心形。
我已对其进行了修改,因此我可以将颜色从红色更改为粉红色。问题是我无法使用thump 动画更改::before 和::after 的颜色。我添加了另一个动画来改变::before 和::after 的颜色。虽然重击可以缩放 ::before 和 ::after 但不能改变颜色。
thum应该改变::before和::after的颜色?
.heart {
width: 100px;
height: 100px;
background-color: pink;
transform: rotate(-45deg);
position: absolute;
left: 100px;
top: 100px;
animation-name: thump;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.heart::before {
content: "";
background-color: pink;
width: 100px;
height: 100px;
border-radius: 50%;
position: absolute;
bottom: 50px;
animation-name: change-color;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.heart::after {
content: "";
background-color: pink;
width: 100px;
height: 100px;
border-radius: 50%;
position: absolute;
left: 50px;
animation-name: change-color;
animation-duration: 2s;
animation-iteration-count: infinite;
}
@keyframes thump {
0% {
transform: scale(1.2) rotate(-45deg);
background-color: red;
}
100% {
transform: scale(1) rotate(-45deg);
background-color: pink;
}
}
@keyframes change-color {
0% {
background-color: red;
}
100% {
background-color: pink;
}
}
<div class="heart"></div>
【问题讨论】:
-
它实际上确实改变了背景,我认为您无法清楚地看到它。将背景从绿色更改为其他颜色,然后您将看到更改。
-
是的,它正在改变背景,但是当你删除
change-color这个动画时它不会改变 -
我没有看到代码有任何问题。最好让它们改变颜色和重击分开。如果您愿意,可以尝试将重击动画添加到
::before和::after,但这也会缩放它们。最好保留thump和change-color用于不同目的。 -
thump正在更改 div 的颜色,但不会更改::before和::after,我是好奇::before和::after由thump缩放但不更改颜色
标签: css css-animations