Loop a pattern of :nth-child styles - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Loop a pattern of :nth-child styles

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
div<!--  w  w w  .  j  a  va  2 s  .co m-->
 {
   width:21px;
   height:21px;
   border:2px solid Chartreuse;
   margin:6px;
}

div:nth-child(1n)
 {
   background-color:yellow;
}

div:nth-child(2n)
 {
   background-color:blue;
}

div:nth-child(3n)
 {
   background-color:pink;
}

div:nth-child(4n)
 {
   background-color:OrangeRed;
}

div:nth-child(5n)
 {
   background-color:grey;
}

div:nth-child(6n)
 {
   background-color:BlueViolet;
}

div:nth-child(7n)
 {
   background-color:Chartreuse;
}

div:nth-child(8n)
 {
   background-color:yellow;
}
</style> 
 </head> 
 <body> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div> 
  <div></div>  
 </body>
</html>

Related Tutorials