HTML CSS examples for CSS Selector:nth-child
Set background using nth-child
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> body {<!--from w w w . ja va 2s.com--> font-family:Georgia; font-size:81%; } ol { list-style:none; } li, li:nth-child(n+15)~li { background:beige; padding:6px; margin:.7em 0; width:201px; } li:nth-child(n+5) { background:teal; } </style> </head> <body> <ol> <li>Lorem ip</li> <li>Lorem ip</li> <li>Lorem ipsu</li> <li>Lorem ips</li> <li>Lorem ips</li> <li>Lorem ip</li> <li>Lorem ipsu</li> <li>Lorem ipsu</li> <li>Lorem ips</li> <li>Lorem ip</li> <li>Lorem ipsum</li> <li>Lorem ipsum</li> <li>Lorem ipsum d</li> <li>Lorem ipsum d</li> <li>Lorem ipsum </li> <li>Lorem ipsum </li> <li>Lorem ipsum do</li> <li>Lorem ipsum d</li> <li>Lorem ipsum d</li> <li>Lorem ipsum</li> </ol> </body> </html>