Looking at a pattern with four article
elements, it appears that using an offset of 4n
can achieve the desired effect. This method is demonstrated in this code snippet (Fiddle):
article {color:blue}
article:nth-child(4n-1), article:nth-child(4n-2) {color:green}
If you prefer to use plus instead of minus, the same outcome can be achieved as shown in this example (Fiddle):
article {color:blue}
article:nth-child(4n+2), article:nth-child(4n+3) {color:green}
To understand the logic behind this approach, it involves shifting the 4n
pattern as illustrated:
-1
and +3
, or -2
and +2
, are congruent mod 4, indicating they refer to the same elements (while technically having different n
values).
This concept can be further explored by coloring elements such as 4n
and 4n+1
blue, as shown in this alternative demonstration (Fiddle):
article {color:green}
article:nth-child(4n), article:nth-child(4n+1) {color:blue}