Search code examples
rowcss-tables

How to color table rows with 3 alternate color


I want a table to display with 3 alternate colors (1-black,2-red,3-white,4-black, 5-red,6-white ....) i tried with nth-child(even) and nth-child(odd) but how to get alternate 3 row colors


Solution

  • Following to the w3c, you try this:

      tr:nth-child(3n+1) {
        background-color: black;
      }
      tr:nth-child(3n+2) {
        background-color: red;
      }
      tr:nth-child(3n) {
        background-color: white;
      }