gpt4 book ai didi

html - css3动画弹跳字母的问题

转载 作者:行者123 更新时间:2023-11-27 22:56:29 26 4
gpt4 key购买 nike

我想在 CSS 中使用动画(跳跃的字母),但显然它不起作用,它自己向上移动的词,但我希望每个字母自己弹跳,告诉我这东西有什么问题??顺便说一句,我是初学者。谢谢!!注意:css 文件是外部文件。

HTML

        <body>
<center>
<div class="txt">
<h1>
<span>H</span>
<span>e</span>
<span>l</span>
<span>l</span>
<span>o</span>
</h1>
</div>
</center>

</body>
</html>

CSS

 body {

background-color: pink;
}

.txt {
position: relative;
top: 300px;
color: black;
font-size: 60px;
font-weight: 500;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
animation: test 2s infinite ;
}

h1 span:nth-child(1) {
animation-delay: 0.25s;
}

h1 span:nth-child(2) {
animation-delay: 0.5s;
}

h1 span:nth-child(3) {
animation-delay: 0.75s;
}

h1 span:nth-child(4) {
animation-delay: 1s;
}

h1 span:nth-child(5) {
animation-delay: 1.25s;
}

@keyframes test {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-25px);
}
100% {
transform: translateY(0);
}
}

最佳答案

您需要将动画放在 span 上,而不是 h1,您还需要向 span 添加显示属性

body {
background-color: pink;
}

.txt {
position: relative;
top: 300px;
color: black;
font-size: 60px;
font-weight: 500;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}

h1 span {
display: inline-block;
animation: test 2s infinite;
}

h1 span:nth-child(1) {
animation-delay: 0.25s;
}

h1 span:nth-child(2) {
animation-delay: 0.5s;
}

h1 span:nth-child(3) {
animation-delay: 0.75s;
}

h1 span:nth-child(4) {
animation-delay: 1s;
}

h1 span:nth-child(5) {
animation-delay: 1.25s;
}

@keyframes test {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-25px);
}
100% {
transform: translateY(0);
}
}
<center>
<div class="txt">
<h1>
<span>H</span>
<span>e</span>
<span>l</span>
<span>l</span>
<span>o</span>
</h1>
</div>
</center>

关于html - css3动画弹跳字母的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59228046/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com