Study · CSS · Patterns
Counting siblings in CSS
Use sibling position and count to space a repeated pattern.
sibling-index() returns an item's one-based position; sibling-count() returns how many items share its parent. Together they place each bar along a wave. Its height, opacity and vertical offset follow that position. Add or remove bars to see the wave redistribute without assigning an index by hand.
--angle: calc((sibling-index() - 1) / sibling-count() * 360deg + var(--phase));
height: calc(22px + (sin(var(--angle)) + 1) / 2 * var(--amplitude));CSS support could not be checked. The default sibling list remains visible.
Amplitude changes the wave’s height; phase shifts it along the row. Where the sibling functions are unavailable, a small JavaScript fallback supplies the same offsets.