News for hackers. Stuff that matters.
Re:Conditional CSS with:has and:nth-last-child by cto_official on Wednesday May 17, 2023 @10:09PM (#35983451)
Sorry stupid question, why are we using nth-last-child vs nth-child ?
Re:Conditional CSS with:has and:nth-last-child by runarberg on Thursday May 18, 2023 @12:47AM (#35984215)
I was wondering the same. I suspect it has to do with the initial hack needing it since it relies on the general sibling selector (~) which selects all following siblings but no preceding siblings, so it is important to catch the very first element and all its following siblings:

    li:nth-last-child(n + 5),
    li:nth-last-child(n + 5) ~ li
I don’t think :has has such limitation and I think a simple :has(:nth-child(5)) would yield the same results as :has(:nth-last-child(n + 5)). :nth-last-child(n + 5) will select the first element among five or more siblings, and :nth-child(5) will simply select the fifth element if it exists. I see no reason to write the former over the latter when you’re just wrapping it inside a :has.