我正在try 将div的每个子级转换为不同的百分比:

#letters:nth-child(n){
    transition: all 1s ease;
    transform: translateX(calc(n*10%));
    transition-delay: calc(n*200ms);
}

transformtransition-delay似乎都不起作用(所有字母的延迟都相等),但值transform也返回错误`Mismatted PARAMETERS().如何修复它?

推荐答案

我更喜欢使用一个css变量:

/* somewhere in base.css to number of maximum children you want to handle, could be generated with SASS for example */

:nth-child(1){
  --child-index: 1;
}

:nth-child(2){
  --child-index: 2;
}

/* your current CSS */
li{
  transform: translateX(calc(var(--child-index)*10%))
}
<ul>
  <li>I'm the first child</li>
  <li>I'm the second child</li>
</ul>

Css相关问答推荐

当optgroup元素不包含任何未使用CSS禁用的选项元素时,如何隐藏它

如何为多个背景和棋盘设置不同的大小

使用SVG以竖排书写模式创建渐变文本时,文本显示异常

如何使用Bootstrap在切换按钮旁边的手风琴标题中添加链接?

在文本之前添加了额外的空间-Angular 树视图CSS

仅 Select 嵌套 div 的底部,而不知道它们的嵌套程度

如何为图像堆叠效果下方的图层实现与磨砂玻璃类似的视觉效果

在 React 中使用 CSS 动画 onClick()

应用填充时边框无法正常工作

使用 :checked 显示隐藏的侧面板

CSS - 等高列?

如何定位 CSS 网格布局中的特定列或行?

Bootstrap:在列之间添加边距/填充空间

如何使用 Bootstrap 3 阻止按钮保持压抑状态

bootstrap 程序中有 7 个相等的列

以原始大小的 50% 显示图像

虚拟键盘激活时的屏幕样式

位置固定宽度 100%

Select 器.class.class和.class.class有什么区别?

CSS 悬停与 JavaScript 鼠标悬停