tags:

views:

31

answers:

3

I would like to apply a style to every row in a table except a specific row (could be the first, or could be one with a unique class or ID - doesn't matter).

How do I do that?

+2  A: 

The easiest cross-browser way is to apply the style then override it, like this:

table tr td { background: blue; }
table tr.someClass td { background: none; }

Since the one with the class, ID, etc is more specific, it'll have the different styling...just put whatever properties you're setting for all rows in that selector so it overrides/reverses the styling. The benefit of this approach is it doesn't need any partially supported (CSS3) selectors, it already works in all browsers.

Nick Craver
The problem with this approach, is that I am currently styling the row I want. So say for instance, I want the bg for all the rows to be #333, but I want the bg for 2nd one to be #eee. Won't the general #333 override the style for the second?
marcamillion
@marcamillion - Nope, not if the styling for the specific row is either more specific (the class or ID does this) or has the same specificity and is declared later in the stylesheet. Like in the above answer, `tr.someClass` is more specific than just `tr`, so *that* `background` rule wins.
Nick Craver
Great! This way will work perfectly then.
marcamillion
+3  A: 

The obvious way would be:

tr { style for most rows; }
tr.specificrow { style for the specific row; }

and then

<table>
...
<tr>...</tr>
<tr class="specificrow">...</tr>
...
</table>
Graeme Perrow
Thanks....got the answer earlier though. +1 for effort :)
marcamillion
+4  A: 

You could use the CSS3 :not() selector. It does exactly what you'd expect it to do.

table tr:not(.special) { color: green }

See this article for more information: The CSS3 :Not() Selector

Alexsander Akers
This is actually what I was looking for....however, the problem is the CSS3 requirement. Nick's answer is most 'cross-browser' friendly. Thanks for this though.
marcamillion