给定了一大组<hr>
html元素,它们在页面加载时应该一个接一个地改变颜色。在动画工作的那一刻,它需要在CSS中为html中的每个新添加的元素添加<hr>
元素,并在CSS中进行大量的重复性手动操作。由于每个下一个<hr>
行的转换时间间隔是相同的,这是否可以在CSS中以更优雅和更短的方式编写?如何将许多CSS动画nth类型的选择器合并为一个?
目标是能够添加新的hr元素而不需要每次都更改CSS。
又一次:这个问题是关于如何在CSS中单独做到这一点(更优雅)? (没有JS/SASS/SCSS)
nav hr{
border-top: 3px solid #BBB;
border-bottom: 0px;
margin: 10px 0;
}
\t
nav hr:nth-of-type(01){animation: .5s ease 0.0s 1 gogo}
nav hr:nth-of-type(02){animation: .5s ease 0.1s 1 gogo}
nav hr:nth-of-type(03){animation: .5s ease 0.2s 1 gogo}
nav hr:nth-of-type(04){animation: .5s ease 0.3s 1 gogo}
nav hr:nth-of-type(05){animation: .5s ease 0.4s 1 gogo}
nav hr:nth-of-type(06){animation: .5s ease 0.5s 1 gogo}
nav hr:nth-of-type(07){animation: .5s ease 0.6s 1 gogo}
nav hr:nth-of-type(08){animation: .5s ease 0.7s 1 gogo}
nav hr:nth-of-type(09){animation: .5s ease 0.8s 1 gogo}
nav hr:nth-of-type(10){animation: .5s ease 0.9s 1 gogo}
nav hr:nth-of-type(11){animation: .5s ease 1.0s 1 gogo}
nav hr:nth-of-type(12){animation: .5s ease 1.1s 1 gogo}
/* Boy this takes a lot of time for every new <hr> added in the html */
@keyframes gogo {
0% {border-top-color: #DDD}
100% {border-top-color: #00F}
}
<nav>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
</nav>
javascript是不是问题?这将是我认为的显而易见的解决方案... – Mikk3lRo
你不能“优雅地”做到这一点,你只需要将它们结合起来。 – TylerH
[保持CSS3动画结束时的最终状态]的可能重复(https://stackoverflow.com/questions/12991164/maintaining-the-final-state-at-end-of-a-css3-animation) – tobiv