This is a frequently asked question, but I would like to point out that the reason :nth-child(n+4):nth-child(-n+6) matches only one specific range of elements, so that it provides only one starting point (n + 4) and one endpoint (-n + 6). The only elements that can be greater than or equal to 4 and less than or equal to 6 are 4, 5, and 6, so it is not possible to combine elements outside this range using the same selector. Adding more aliases :nth-child() only limit matches.
The solution is to think about it in terms of columns, assuming that there will always be exactly 3 columns (elements) for each row. You have three columns, so you will need three separate aliases :nth-child() . Elements 4 and 10 from the first column are divided into 6 elements, so the argument to all the aliases :nth-child() should start with 6n.
The + b part in the An + B expression can be equal to +4, +5 and +6 or 0, -1 and -2 - they will coincide with the same set of elements:
li:nth-child(6n+4), li:nth-child(6n+5), li:nth-child(6n+6)li:nth-child(6n), li:nth-child(6n-1), li:nth-child(6n-2)
You cannot do this with a single pseudo-class :nth-child() or one compound selector, consisting of any combination :nth-child() pseudos, because the An + B notation simply does not allow creating expressions that correspond to elements in ranges as described.
source share