Skip to content

Instantly share code, notes, and snippets.

@jonrandy
Created February 6, 2023 03:43
Show Gist options
  • Save jonrandy/f59cf070dec675109cbdb23539826487 to your computer and use it in GitHub Desktop.
Save jonrandy/f59cf070dec675109cbdb23539826487 to your computer and use it in GitHub Desktop.
An nth-child CSS trick
:nth-child(1) { --nth-child: 1 }
:nth-child(2) { --nth-child: 2 }
:nth-child(3) { --nth-child: 3 }
:nth-child(4) { --nth-child: 4 }
:nth-child(5) { --nth-child: 5 }
/* ... */
* {
background-color: hsl(calc(100 * var(--nth-child)) 100% 40%);
}
.class {
/* We want to start counting at 0 */
--v: var(--nth-last-child) - 1;
opacity: 1 - calc(var(--v) * 0.15);
transform:
translate3d(
50%,
calc(-5px * var(--v)),
calc(-1px * var(--v))
scale(calc(1 - var(--v) * 0.05);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment