【发布时间】:2019-05-16 17:21:42
【问题描述】:
我用 CSS 制作了一颗心,并让它像往常一样调整大小,每秒钟变小 - 变大。但我注意到了这种奇怪的摆动,我并没有真正放在那里,看着真的很痛苦。我知道很少有可能重复的问题,但它们并没有真正帮助。这是fiddle。
html,
body,
.container {
height: 100%;
}
.container {
display: flex;
justify-content: center;
align-items: center;
}
.heart {
display: flex;
justify-content: center;
align-items: center;
background-color: red;
transform: rotate(-45deg);
transform-style: preserve-3d;
animation: growMain 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
.heart:after,
.heart:before {
background-color: red;
content: "";
border-radius: 50%;
position: absolute;
transform: translateZ(-1px);
}
.heart:after {
animation: growAfter 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
.heart:before {
animation: growBefore 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
@keyframes growMain {
from {
width: 50px;
height: 50px;
}
to {
width: 80px;
height: 80px;
}
}
@keyframes growAfter {
from {
left: 25px;
width: 50px;
height: 50px;
}
to {
left: 40px;
width: 80px;
height: 80px;
}
}
@keyframes growBefore {
from {
top: -25px;
width: 50px;
height: 50px;
}
to {
top: -40px;
width: 80px;
height: 80px;
}
}
.inner {
display: initial;
transform: rotate(45deg);
}
.text {
text-align: center;
color: white;
font-family: "Comic Sans MS";
font-size: 100%;
margin: 0;
}
<div class="container">
<div class="heart">
<div class="inner">
<p class="text">Some text</p>
</div>
</div>
</div>
【问题讨论】:
-
什么问题?
-
它像疯了一样摇晃@DogukanCavus,至少在 Opera 和 Chrome 中,即使我没有在我的代码中编写它。也许在其他浏览器中不会发生
-
"...即使我没有在我的代码中写下它" - 我能给出的最好的建议是你应该总是在你的问题中描述你的问题,否则我们应该如何提供帮助?
-
@DavidThomas 我确实做到了,但我怎么知道问题是否也出现在您的浏览器上。正如我所说,心脏在颤抖,一点点但你可以看到它,看着很痛苦
标签: html css css-animations