跳到正文
原文
Smashing Magazine· [email protected] (Durgesh Pawar)·· 2026-05-21AI 评分34

CSS 高级树计数:使用 `sibling-index()` 和 `sibling-count()` 进行布局

Advanced Tree Counting: Mathematical Layouts With `sibling-index()` And `sibling-count()`

AI 导读

CSSWG 正讨论为 `sibling-index()` 增加 `of` 参数,使其能够按选择器计算匹配兄弟元素的序号,相关扩展记录于 issue #9572。按规划,`sibling-index(of .active)` 可让元素返回其在 `.active` 兄弟中的序号,而无需操作 DOM;`children-count()` 和 `descendant-count()` 也仍在提案阶段。

来源:Smashing Magazine · smashingmagazine.com