有没有一种方法可以使用n个类型中的n个来计算某种样式?
我正在制作照片滑块,并且部分css当前如下所示:
.container *:nth-of-type(1) img{
object-position: 0%;
}
.container *:nth-of-type(2) img{
object-position: calc(100% / 9 * 1);
}
.container *:nth-of-type(3) img{
object-position: calc(100% / 9 * 2);
}
.container *:nth-of-type(4) img{
object-position: calc(100% / 9 * 3);
}
.container *:nth-of-type(5) img{
object-position: calc(100% / 9 * 4);
}
.container *:nth-of-type(6) img{
object-position: calc(100% / 9 * 5);
}
.container *:nth-of-type(7) img{
object-position: calc(100% / 9 * 6);
}
.container *:nth-of-type(8) img{
object-position: calc(100% / 9 * 7);
}
.container *:nth-of-type(9) img{
object-position: calc(100% / 9 * 8);
}
.container *:nth-of-type(10) img{
object-position: 100%;
}
这很容易用js生成,但我希望使用仅CSS的解决方案。这可能吗?