External Publication
Visit Post

Quantity queries using has() selector

Jonathan Stephens April 29, 2026
Source
Really useful calculator to help create the quantity queries for selectors. Put in the element being queried, set quantity (exactly, at least, at most, between), the children elements, and wahlah. The example: .container:has(> :nth-last-child(3):nth-child(-n + 8)) { /* */ /* your CSS here */ /* */ } Also, two useful quantity selectors too: /* select .container if it has an even number of child elements */ .container:has(> :last-child:nth-child(even)) { /* your CSS here */ } /* select .container if it has an odd number of child elements */ .container:has(> :last-child:nth-child(odd)) { /* your CSS here */ }

Discussion in the ATmosphere

Loading comments...