Some Extremely Handy `:nth-child` Recipes as Sass Mixins | CSS-Tricks

There is no such thing as one-size-fits-all styling. An image gallery with three images might need to be styled differently than an image gallery with twelve. There are some cool tricks that you can use to add some number-based logic to your CSS! Using :nth-child and :nth-last-child, you can get some surprisingly complex information without ever leaving your stylesheet.

This post will assume that you have a basic understanding of how the :nth-child pseudo-selector works. If you need a quick refresher, Chris has a great post covering that topic.

Source: Some Extremely Handy `:nth-child` Recipes as Sass Mixins | CSS-Tricks