gpt4 book ai didi

html - 仅使用 CSS 顺序显示 HTML 部分

转载 作者:行者123 更新时间:2023-11-28 16:02:29 25 4
gpt4 key购买 nike

请参阅下面的 HTML 代码。哪些 CSS 代码将实现以下功能:

加载时,第一个部分显示指定的时间段然后消失。然后第二部分显示指定的时间段然后消失;然后是第三节,然后是第四节,方式与前几节相同。整个过程重复。

section {margin: 50px 40%;}
<section id="one">
<div class="content">Some stuff</div>
</section>
<section id="two">
<div class="content">Some other stuff</div>
</section>
<section id="three">
<div class="content">More of the same</div>
</section>
<section id="four">
<div class="content">Ditto</div>
</section>

最佳答案

看看CSS animations .您可以使用关键帧来隐藏和显示您的部分,如下所示:

@keyframes show{
0% {opacity: 0}
10% {opacity: 1}
25% {opacity: 0}
}

然后,您可以使用animation-delay 来延迟每个部分的开始:

#one{
opacity: 0;
animation: show 40s infinite;
}
#two{
opacity: 0;
animation: show 40s infinite;
animation-delay: 10s;
}
#three{
opacity: 0;
animation: show 40s infinite;
animation-delay: 20s;
}
#four{
opacity: 0;
animation: show 40s infinite;
animation-delay: 30s;
}

通过一些调整和数学运算,您可以获得想要的结果!

我的代码片段:

@keyframes show{
0% {opacity: 0}
10% {opacity: 1}
25% {opacity: 0}
}

#one{
opacity: 0;
animation: show 40s infinite;
}
#two{
opacity: 0;
animation: show 40s infinite;
animation-delay: 10s;
}
#three{
opacity: 0;
animation: show 40s infinite;
animation-delay: 20s;
}
#four{
opacity: 0;
animation: show 40s infinite;
animation-delay: 30s;
}
<body>
<style>
section {
margin: 50px 40%;
}
</style>
<section id="one">
<div class="content">Some stuff</div>
</section>
<section id="two">
<div class="content">Some other stuff</div>
</section>
<section id="three">
<div class="content">More of the same</div>
</section>
<section id="four">
<div class="content">Ditto</div>
</section>
</body>

关于html - 仅使用 CSS 顺序显示 HTML 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58252048/

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