News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Using background-color on tr's... bad idea?

Started by [Unknown], October 24, 2003, 02:33:03 AM

Previous topic - Next topic

[Unknown]

Alright, assuming I have to use a table and this is for the heading column.... sometimes you want to apply to classes to a td, or save bandwidth by not specifying for each.  Example: (and yeah, th is better - whatever.)

<tr>
  <td class="titlebg"><span class="text1">HEADING A</span></td>
  <td class="titlebg"><span class="text1">HEADING B</span></td>
  <td class="titlebg"><span class="text1">HEADING C</span></td>
</tr>


Could be, in practice...

<tr class="titlebg">
  <td class="text1">HEADING A</td>
  <td class="text1">HEADING B</td>
  <td class="text1">HEADING C</td>
</tr>


However, I worry that this is "bad practice" - does it work in all browsers?  It seems to, but I haven't tested it on MSIE 4.x...

Any comments?  Should I not do this?

-[Unknown]

SparkieGeek

Quote from: [Unknown] on October 24, 2003, 02:33:03 AM
Alright, assuming I have to use a table and this is for the heading column.... sometimes you want to apply to classes to a td, or save bandwidth by not specifying for each.  Example: (and yeah, th is better - whatever.)

<tr>
  <td class="titlebg"><span class="text1">HEADING A</span></td>
  <td class="titlebg"><span class="text1">HEADING B</span></td>
  <td class="titlebg"><span class="text1">HEADING C</span></td>
</tr>


Could be, in practice...

<tr class="titlebg">
  <td class="text1">HEADING A</td>
  <td class="text1">HEADING B</td>
  <td class="text1">HEADING C</td>
</tr>


However, I worry that this is "bad practice" - does it work in all browsers?  It seems to, but I haven't tested it on MSIE 4.x...

Any comments?  Should I not do this?

-[Unknown]

Can you not just drop the class IDs on the <td> elements and access them through a CSS rule like this:

tr.titlebg td {background-color: blah}


in plain English "Set the background colour of all <td>s that are descendants of a <tr class="titlebg"> to blah"

N.B. This is completely untested, just trying to squeeze out those "pointless" (IMO) class IDs. It's valid CSS and works in Gecko, I'm not sure how IE or Opera cope though.

SparkieGeek

Quote from: SparkieGeek on October 24, 2003, 07:16:06 AM
N.B. This is completely untested, just trying to squeeze out those "pointless" (IMO) class IDs. It's valid CSS and works in Gecko, I'm not sure how IE or Opera cope though.

This CSS support reference indicates that it should work across the board (apart from NN 4.x)

[Unknown]

Quote from: SparkieGeek on October 24, 2003, 07:24:28 AM
This CSS support reference indicates that it should work across the board (apart from NN 4.x)

Thank you - looks like a nice reference.  And I really like your suggestion about tr/td.

But that could make it much clearer... much... (imho)

Thanks again,
-[Unknown]

Advertisement: