i

Learn HTML and CSS in 10 Days

Table Striping

To make the table much more legible, one common practice is to "stripe" the tows of the table with alternating color in the background. This clears up the row and offers visual cue for the information to be scanned. One popular method is to keep a class on every element and give a background color to that class. Another method is to use the: nth-child pseudo-class selector along with an odd or even argument to choose every other element.

In the code below, the table of books utilize nth-child pseudo-class selector along with an even argument to choose all even rows of the table and provide a grey background.

table {

  border-collapse: separate;

  border-spacing: 0;

}

th,

td {

  padding: 10px 15px;

}

thead {

  background: #395870;

  color: #fff;

}

tbody tr:nth-child(even) {

  background: #f0f0f2;

}

td {

  border-bottom: 1px solid #cecfd5;

  border-right: 1px solid #cecfd5;

}

td:first-child {

  border-left: 1px solid #cecfd5;

}