使用交替的行颜色覆盖表格内单行上的行颜色

hya*_*ion 10 html css css3

我有一个CSS3交替行样式的表,但我需要覆盖几行的样式.

这是表格的CSS:

table.primary tr:nth-child(odd) {
    background-color: #e5e5e5;
}
table.primary tr:nth-child(even) {
    background-color: #ededed;
}
Run Code Online (Sandbox Code Playgroud)

我需要覆盖一些具有非常不同的背景颜色(和其他格式)的行,我希望只添加一个class=到各个行,但似乎这不会覆盖上面的CSS.

例如

<table class="primary">
    <tr><td>one</td></tr>
    <tr class="new"><td>two</td></tr>
    <tr><td>three</td></tr>
</table>
Run Code Online (Sandbox Code Playgroud)

或者我需要跳过CSS3和只使用一个class="row1",class="row2",class="new"来代替.

关于如何覆盖nth-child类的任何建议?

Bol*_*ock 18

类和伪类共享相同的特殊性,它应该足以定义.new样式规则:nth-child()这样的规则,假设一个类是overidde所有其他样式:

table.primary tr:nth-child(odd) {
    background-color: #e5e5e5;
}
table.primary tr:nth-child(even) {
    background-color: #ededed;
}
table.primary tr.new {
    background-color: #ffc;
}
Run Code Online (Sandbox Code Playgroud)

jsFiddle演示