So, I have this query to get last-child when there are 7 or more elements
li:nth-last-child(7) ~ li:last-child { background: red; }
This works for any number of elements if at least 7 exists. I want to do the opposite, get first-child .
I tried the following
li:nth-last-child(7) ~ li:first-child { background: red; }
But that does not work. Strange I can get the second child using the following
li:nth-last-child(7) ~ li:nth-child(2) { background: red; }
I know this is pretty complicated CSS, and it may even be impossible, but I wonder if this can be done. I would prefer not to use JS, if at all possible. I suppose this is a challenge as a challenge;)
source share