This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis
Just parking this CSS snippet on my blog for my future self. 🙈
If you want to select elements only when there's a given number of them, you can use :nth-last-child()
combination.
The following selector combination is called a "quantity query".
li:nth-last-child(n+3),
li:nth-last-child(3) ~ li {
color: red;
}
See it in action below. 👇
[Interactive component: visit the article to see it...]
Reply to Stefan
This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis
Stefan Judis | Sciencx (2022-07-26T22:00:00+00:00) The CSS quantity query with :nth-last-child() (#snippet). Retrieved from https://www.scien.cx/2022/07/26/the-css-quantity-query-with-nth-last-child-snippet/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.