I’m wondering if there is a way to alternate the background colors of product blocks in Shopify via editing shop code. Here’s an example of what that would look like:
How it is set up right now is this same grid but just with a black background for everything, with white lines separating the blocks. Is there a way to tell the background color to be white with every other product, or something similar?
3
Answers
See
:nth-child
pseudo class :https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child
For example
tr:nth-child(even)
ortr:nth-child(2n)
Represents the even rows of an HTML table: 2, 4, 6, etc.
The easiest is to apply CSS in a
:nth-child
pseudo-class. Just put all of your styles in there.Your best bet is to use the
:nth-child
pseudo-class. This can bedone in a number of ways. If I were you, I’d go with:
An example of the :nth-child(eve) selector in action
Those are just two of the ways, but like I said before – you have many
options to chose from. If you want to see some examples or learn more
about the :nth-child pseudo-class, I suggest checking out the
pseudo-class page on CSS Tricks
Good Luck!