This question already has an answer here:
I have seen this image showing a very nice table:
I have html code that gives color to every even line. Every year column and subcolumns have a color too. Is there a way to have a new different mixed color for the cells in year coluns and even rows and a new different mixed color for the cells in year coluns and odd rows, just like in the picture? I do not want to use something like:
.mixed_odd {background-color: #44ff99}
.mixed_even {background-color: #99ff99}
because my page will have many rows, more than 200 in some cases and it takes a lot of time to set the color to those columns manually. Is there a fast css way to do it like in the picture?
table {
font-family: arial, sans-serif;
border-collapse: collapse;
}
.beta td {
text-align: center;
}
TH.Title {
background-color: #A0E0A0
}
tr:nth-child(even) {
background-color: #bbffcc;
}
.Year2016 {
background-color: #ffff99
}
.Year2017 {
background-color: #ccff99
}
.Year2018 {
background-color: #ffff99
}
<TABLE class="beta" cellspacing="2" cellpadding="6" border="1">
<TR>
<TH class="Title" rowspan="2">code</TH>
<TH class="Title" rowspan="2">Text</TH>
<TH class="Title" rowspan="2">Text</TH>
<TH class="Title" rowspan="2">Text</TH>
<TH class="Title" rowspan="2">Text</TH>
<th class="Year2016" colspan="2">2016 Items</th>
<th class="Year2017" colspan="2">2017 items</th>
<th class="Year2018" colspan="2">2018 Items</th>
</tr>
<TR>
<TH class="Year2016">Item 1</TH>
<TH class="Year2016">Item 2</TH>
<TH class="Year2017">Item 1</TH>
<TH class="Year2017">Item 2</TH>
<TH class="Year2018">Item 1</TH>
<TH class="Year2018">Item 2</TH>
</TR>
<TR>
<TD>1</TD>
<TD>text 1</TD>
<TD>text 2</TD>
<TD>text 3</TD>
<TD>text 4</TD>
<TD class="Year2016">5</TD>
<TD class="Year2016">6</TD>
<TD class="Year2017">7</TD>
<TD class="Year2017">8</TD>
<TD class="Year2018">9</TD>
<TD class="Year2018">10</TD>
</TR>
<TR>
<TD>1</TD>
<TD>text 1</TD>
<TD>text 2</TD>
<TD>text 3</TD>
<TD>text 4</TD>
<TD class="Year2016">5</TD>
<TD class="Year2016">6</TD>
<TD class="Year2017">7</TD>
<TD class="Year2017">8</TD>
<TD class="Year2018">9</TD>
<TD class="Year2018">10</TD>
</TR>
<TR>
<TD>1</TD>
<TD>text 1</TD>
<TD>text 2</TD>
<TD>text 3</TD>
<TD>text 4</TD>
<TD class="Year2016">5</TD>
<TD class="Year2016">6</TD>
<TD class="Year2017">7</TD>
<TD class="Year2017">8</TD>
<TD class="Year2018">9</TD>
<TD class="Year2018">10</TD>
</TR>
<TR>
<TD>1</TD>
<TD>text 1</TD>
<TD>text 2</TD>
<TD>text 3</TD>
<TD>text 4</TD>
<TD class="Year2016">5</TD>
<TD class="Year2016">6</TD>
<TD class="Year2017">7</TD>
<TD class="Year2017">8</TD>
<TD class="Year2018">9</TD>
<TD class="Year2018">10</TD>
</TR>
</TABLE>