The CSS selector to select n-th child element inside an another parent element would look something like this. Let's say you want to target the 5th p tag inside a div with the class post-content div.post-content p:nth-of-type(5) More examples of using nth-of-type css selector. Select the first p element inside a div element: div p:nth-of-type(1) { /* your styles here */ } Select every even li element inside a ul element: ul li:nth-of-type(even) { /* your styles here */ } Select every third h2 element inside a section element: section h2:nth-of-type(3) { /* your styles here */ } Select the last span element inside a div element: div span:nth-last-of-type(1) { /* your styles here */ } Select the 2nd to 4th input elements inside a form element: form input:nth-of-type(n+2):nth-of-type(-n+4) { /* your styles here */ } In each of these examples, the :nth-of-type() selector is used to target a specific type of element based on its position in the parent element.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners