Skip to main content
CSS-Tricks
  • Articles
  • Alamanac
  • Guides
  • Videos
  • Books
  • Newsletter
Search

Articles Tagged
nth-child

9 Articles
{
,

}
Direct link to the article Implicit Grids, Repeatable Layout Patterns, and Danglers
:has grid implicit grid nth-child

Implicit Grids, Repeatable Layout Patterns, and Danglers

Dave Rupert with some modern CSS magic that tackles one of those classic conundrums: what happens when the CSS for component is unable to handle the content we throw at it?

The specific situation is when a layout grid expects …

Avatar of Geoff Graham
Geoff Graham on Aug 2, 2022
Direct link to the article Conditionally Styling Selected Elements in a Grid Container
grid nth-child pseudo elements

Conditionally Styling Selected Elements in a Grid Container

Calendars, shopping carts, galleries, file explorers, and online libraries are some situations where selectable items are shown in grids (i.e. square lattices). You know, even those security checks that ask you to select all images with crosswalks or whatever.…

Avatar of Preethi
Preethi on Jun 15, 2022
Direct link to the article CSS Pseudo Commas
copywriting lists nth-child pseudo elements

CSS Pseudo Commas

A bonafide CSS trick if there ever was one! @ShadowShahriar created a CodePen demo that uses pseudo-elements to place commas between list items that are displayed inline, and the result is a natural-looking complete sentence with proper punctuation.…

Avatar of Geoff Graham
Geoff Graham on Aug 30, 2021 (Updated on Sep 27, 2021)
Direct link to the article :nth-child Between Two Fixed Indexes
nth-child pseudo classes

:nth-child Between Two Fixed Indexes

I needed to select some elements between two fixed indexes the other day — like literally the second through fifth elements. Ironically, I have a whole post on “Useful :nth-child Recipes” but this wasn’t one of them.

The answer, it …

Avatar of Chris Coyier
Chris Coyier on Jun 29, 2021
Direct link to the article Pseudo-Randomly Adding Illustrations with CSS
nth-child

Pseudo-Randomly Adding Illustrations with CSS

Between each post of Eric Meyer’s blog there’s this rather lovely illustration that can randomly be one of these five options:…

Avatar of Robin Rendle
Robin Rendle on Apr 17, 2020 (Updated on Apr 18, 2020)
Direct link to the article CSS :nth-of-class selector
nth-child

CSS :nth-of-class selector

That’s not a thing.

But it kinda is!

Bram covers how frustrating .bar:nth-child(2) is. It’s not “select the second element of class .bar.” It’s “select the second element if it also has the class .bar.” The good news? …

Avatar of Chris Coyier
Chris Coyier on Mar 23, 2020
Direct link to the article Staggered CSS Transitions
hover nth-child Sass transition-delay

Staggered CSS Transitions

Let’s say you wanted to move an element on :hover for a fun visual effect.

@media (hover: hover) {
  .list--item {
    transition: 0.1s;
    transform: translateY(10px);
  }
  .list--item:hover,
  .list--item:focus {
    transform: translateY(0);
  }
}

Cool cool. But what if you had …

Avatar of Chris Coyier
Chris Coyier on Aug 14, 2019
Direct link to the article Some Extremely Handy `:nth-child` Recipes as Sass Mixins
nth-child

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

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 …

Avatar of Adam Giese
Adam Giese on May 17, 2017 (Updated on May 24, 2017)
Direct link to the article Cicada Principle and CSS
cicada nth-child

Cicada Principle and CSS

Charlotte Jackson uses this classic clever technique to pseudo randomize border-radius, making irregular circles for a photo grid.

A cicada is a rather grim looking little bug. You may have heard of them. There is a kind called the Periodical

…
Avatar of Chris Coyier
Chris Coyier on Oct 7, 2016

CSS-Tricks is powered by DigitalOcean.

Keep up to date on web dev

with our hand-crafted newsletter

DigitalOcean
  • About DO
  • Cloudways hosting
  • Legal stuff
  • Get free credit!
CSS-Tricks
  • Write for us!
  • Advertise with us
  • Contact us
Social
  • RSS Feeds
  • CodePen
  • Mastodon
  • X
Back to Top