【发布时间】:2022-03-11 04:13:06
【问题描述】:
我正在尝试这样当我打开页面时,test 将显示为红色,testing 将显示为白色。当我想要保留的页面打开时,我使用了延迟(如果您运行程序,您会看到)。
CSS
#hero h1 {
display: block;
width: fit-content;
font-size: 3rem;
position: relative;
color: transparent;
animation: text_reveal .5s ease forwards;
animation-delay: 1s;
}
#hero h1 .slide {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 0;
background-color: crimson;
animation: text_reveal_box 1s ease;
animation-delay: .5s;
}
/* KetFrames */
@keyframes text_reveal_box {
50% {
width: 100%;
left: 0;
}
100% {
width: 0;
left: 100%;
}
}
@keyframes text_reveal {
100% {
color: white;
}
}
HTML
<section id="hero">
<div class="hero container">
<div>
<h1><span class="red">test</span> testing<span class="slide"></span></h1>
</div>
</div>
</section>
【问题讨论】:
-
为什么不让红色类的跨度有颜色:红色;在 CSS 中。我想这就是你想要的
-
颜色来自文字显示
-
@Naman 似乎是一个简单的解决方案,但是当动画发生时,就会有红色文本坐在那里。
-
好吧,给 z-index: 10;滑动到所有东西的顶部。
-
@Naman 仍然会有红色文本坐在那里...因为动画设置了延迟。
标签: html css css-animations keyframe