How to define a class for table to control the style of table rows

newbie picture newbie · Jan 22, 2014 · Viewed 57.4k times · Source

I'm wondering if I can define a class that could also control the row styles within the table.

Lets say I define a class "aTable"

.aTable
{
  width:800px;
  border-spacing:2px;
}

I also want to define the row styles. So when I assign this class to a table, all the rows in that table would follow the design, let say background-color:#e9e9e9;

Answer

dfsq picture dfsq · Jan 22, 2014

You can achieve it like this:

.aTable {
    width: 800px;
    border-spacing: 2px;
}
.aTable tr {
    background-color: #DDD;
}