I'm looking for a way to select columns in a CSS grid. I found a way to select a column in a static grid, using the :nth-child()
selector. For example: in a 3 column grid, :nth-child(2)
will select every grid item in the second column.
However, this doesn't work when you have a responsive grid with three media queries like I do. My grid has 24 grid items. On mobile devices, the content is displayed in a 3 column by 8 row grid. On tablets, it is displayed in a 4 by 6 grid and so on. I need a way to select the 3rd column for example, no matter if there are 8 rows or 6.
It's kind of a hard problem to explain, let me know if i need to clarify further. There's no possible solution with CSS that i can think of, so it will probably be a JavaScript or jQuery solution. Here's my CodePen to illustrate the kind of grid system I'm working with.