Question

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;

Was it helpful?

Solution

You can achieve it like this:

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

OTHER TIPS

To give a whole row a background-color your would assign the background-color to each cell in that row, i.e.

.aTable tr td { background-color: #e9e9e9: }

You can always select specific classes or elements within a css class definition like that.

I love to use less to make CSS a lot easier and cleaner. Then you could do this:

.aTable {
    width: 800px;
    border-spacing: 2px;
    tr {
        background-color: #DDD;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top