HTML CSS examples for CSS Selector:nth-child
Target :nth-child after a certain class using ~
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> * {<!--from w w w . j a v a2s. co m--> padding:0; margin:0; list-style:none; box-sizing:border-box; } .ctn li { width:100%; height:51px; background:lightgrey; border-bottom:2px solid Chartreuse; } li.is-middle~li:nth-child(3n) { background:purple; } li.is-middle~li:nth-child(3n+1) { background:green; } li.is-middle~li:nth-child(3n+2) { background:yellow; } </style> </head> <body> <ul class="ctn"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li class="is-middle"></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </body> </html>