W3 Mind Logo
Home » :nth-child() Selector – CSS3

:nth-child() Selector – CSS3

:nth-child

				
					li:nth-child(5) {
    background-color: #ff00ff;
}
				
			

Using :nth-child(5) it allows you to specifically choose to change only the 5th element in the parent element.

Example:

  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here

Positive Child Ranges

				
					li:nth-child(n+5) {
    background-color: #ffff00;
}
				
			

Using the :nth-child(n+5) like this allows you pick :nth-child(5) and above.

Example:

  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here

Negative Child Ranges

				
					li:nth-child(-n+5) {
    background-color: #ff0000;
}
				
			

Using the :nth-child(-n+5) like this allows you pick :nth-child(5) and below.

Example:

  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
  • Some Text Here
About Author
W3Mind

W3Mind

W3Mind focuses on Blogging, Make Money Online, SEO, Business Blogging, Social Media, WordPress, Internet Tools, Web Design and Development.
Give it a Share
Facebook
Twitter
LinkedIn
You May Also Like
Leave a Reply

Your email address will not be published. Required fields are marked *

How to
START A
BLOG
(step by step)
Load WordPress Sites in as fast as 37ms!