Как раскрасить такую таблицу?

Нельзя использовать :nth-chil(i), :nth-child(an+b) и :not. Только odd, first, last и even.

Шахматная доска


Ответы (1 шт):

Автор решения: Igor

var row = "";
for (var i = 0; i < 10; i++)
  row += "<td/>";
row = "<tr>" + row + "</tr>";

var html = "";
for (var i = 0; i < 10; i++)
  html += row;

document.getElementById("board").innerHTML = html;
#board {
  background: gray;
}

#board td {
  width: 40px;
  height: 40px;
}

#board tr:nth-child(odd) td:nth-child(even),
#board tr:nth-child(even) td:nth-child(odd) {
  background: black;
}

#board tr:nth-child(even) td:nth-child(even),
#board tr:nth-child(odd) td:nth-child(odd) {
  background: white;
}

#board tr:first-child td:nth-child(even),
#board tr:first-child td:nth-child(odd),
#board tr:last-child td:nth-child(even),
#board tr:last-child td:nth-child(odd),
#board tr:nth-child(odd) td:first-child,
#board tr:nth-child(even) td:first-child,
#board tr:nth-child(odd) td:last-child,
#board tr:nth-child(even) td:last-child
{
  background: lightgreen;
  width: 10px;
  height: 10px;
}
<table id="board"></table>

→ Ссылка