{"id":366252,"date":"2022-06-15T07:15:50","date_gmt":"2022-06-15T14:15:50","guid":{"rendered":"https:\/\/css-tricks.com\/?p=366252"},"modified":"2022-06-15T07:15:52","modified_gmt":"2022-06-15T14:15:52","slug":"conditionally-styling-selected-elements-in-a-grid-container","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/conditionally-styling-selected-elements-in-a-grid-container\/","title":{"rendered":"Conditionally Styling Selected Elements in a Grid Container"},"content":{"rendered":"\n

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.<\/p>\n\n\n\n\n\n\n\n

\"\"
🧐<\/figcaption><\/figure>\n\n\n\n

I found a neat way to display selectable options in a grid. No, not recreating that reCAPTCHA, but simply being able to select multiple items. And when two or more adjoining items are selected, we can use clever :nth-of-type<\/code> combinators, pseudo elements, and the :checked<\/code> pseudo-class to style them in a way where they look grouped together.<\/p>\n\n\n\n