【发布时间】:2017-10-18 19:54:03
【问题描述】:
鉴于大量<hr> html 元素在页面加载时应该一个接一个地改变颜色。目前动画可以工作,但是对于html中每个新添加的<hr>元素,它需要在CSS中进行大量重复的手工劳动。由于每个下一个<hr> 行的转换间隔都是相同的,这是否可以在 CSS 中以更优雅和更短的方式编写?
目标是能够添加新的 hr 元素无需每次都更改 CSS。
再次:这个问题是关于如何仅在 CSS 中做到这一点(更优雅)? (没有 js/sass/scss)
nav hr{
border-top: 3px solid #BBB;
border-bottom: 0px;
margin: 10px 0;
}
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>
JSFiddle Demo
【问题讨论】:
-
javascript 是不可能的吗?我认为这将是显而易见的解决方案......
-
你不能“优雅”地做到这一点,你必须把它们结合起来。
标签: html css animation css-selectors css-animations