Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / July 2008



Tip: Looking for answers? Try searching our database.

Zebra Table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bruce A. Julseth - 29 Jul 2008 21:11 GMT
I am trying to create a Zebra table where each Zebra "Strip" consists of two
rows.  I am using a classical table to create the Zebra table. In my CSS, I
have

.dark {
background-color: #00FFFF;
}

.light {
background-color: #CCFFFF;
}

  <tr class="light ">
   <td class="name">Name</td>
   <td class="addr">Street</td>
   <td class="email">Email</td>
   <td class="interest">Interests</td>
  </tr>
  <tr class="light ">
   <td>Spouse</td>
   <td>Telephone</td>
   <td>Spouse Email</td>
   <td>Spouse Interests</td>
  </tr>

  <tr class="dark">
   <td class="name">Joe</td>
   <td class="addr">Elm</td>
   <td class="email">Something</td>
   <td class="interest">More</td>
  </tr>
  <tr class="dark">
   <td>Jane</td>
   <td>999 999-9999</td>
   <td>Something Email</td>
   <td>Something Interests</td>
  </tr>

I would to wrap the two rows in a single definition, like with a <div> or a
<span> but having been able to make that work.

<div class="light">
  <tr>
   <td class="name">Name</td>
   <td class="addr">Street</td>
   <td class="email">Email</td>
   <td class="interest">Interests</td>
  </tr>
  <tr class="light ">
   <td>Spouse</td>
   <td>Telephone</td>
   <td>Spouse Email</td>
   <td>Spouse Interests</td>
  </tr>
</div>

<div class="dark">
  <tr>
   <td class="name">Joe</td>
   <td class="addr">Elm</td>
   <td class="email">Something</td>
   <td class="interest">More</td>
  </tr>
  <tr class="dark">
   <td>Jane</td>
   <td>999 999-9999</td>
   <td>Something Email</td>
   <td>Something Interests</td>
  </tr>
</div>

Appreciate your help.  Thanks...

Bruce
Bruce A. Julseth - 29 Jul 2008 21:20 GMT
>I am trying to create a Zebra table where each Zebra "Strip" consists of
>two rows.  I am using a classical table to create the Zebra table. In my
[quoted text clipped - 70 lines]
>
> Bruce

I think I found the solution..

Adding

span.dark tr {
background-color: #00FFFF;

}

span.light tr {
background-color: #CCFFFF;
}

seems to be doing the trick.. Thanks...
Bruce A. Julseth - 29 Jul 2008 21:28 GMT
>>I am trying to create a Zebra table where each Zebra "Strip" consists of
>>two rows.  I am using a classical table to create the Zebra table. In my
[quoted text clipped - 85 lines]
>
> seems to be doing the trick.. Thanks...

Nope.. It didn't work.. Sorry. Can someone out there in CSS land help me?

Thanks and sorry for the false alarm. It worked fine in Dreamweaver, but
failed in Safari both on my localhost and when I upload it.
Johannes Koch - 29 Jul 2008 21:43 GMT
Bruce A. Julseth schrieb:

>>   <tr class="light ">
>>    <td class="name">Name</td>
[quoted text clipped - 8 lines]
>>    <td>Spouse Interests</td>
>>   </tr>

Looks like these are header cells. So use the th element!

>>   <tr class="dark">
>>    <td class="name">Joe</td>
[quoted text clipped - 8 lines]
>>    <td>Something Interests</td>
>>   </tr>

It can/will be difficult for a screen reader user to find out which
column header cells belong to which data cell. You can associate them
via td/@headers and th/@id.

>> <div class="dark">
>>   <tr>
[quoted text clipped - 10 lines]
>>   </tr>
>> </div>

Neither can div be a parent element of tr, ...

> I think I found the solution..
>
[quoted text clipped - 4 lines]
>
> }

... nor can span.

However, tbody can.

Signature

Johannes Koch
In te domine speravi; non confundar in aeternum.
                            (Te Deum, 4th cent.)

Bruce A. Julseth - 29 Jul 2008 22:11 GMT
> Bruce A. Julseth schrieb:
>
[quoted text clipped - 59 lines]
>
> However, tbody can.

Thanks for the suggestion on using <th>. I've never used tbody so I'll have
to study how to use it, as well as td/@headers and th/@id.
.
Hope this helps. If anyone else has a suggestion, please send them to me.

Bruce
Johannes Koch - 29 Jul 2008 23:07 GMT
Bruce A. Julseth schrieb:
> Thanks for the suggestion on using <th>. I've never used tbody so I'll have
> to study how to use it, as well as td/@headers and th/@id.

See the chapter on tables
(<http://www.w3.org/TR/html4/struct/tables.html>) in the HTML 4.01
specification for tbody
(<http://www.w3.org/TR/html4/struct/tables.html#h-11.2.3>), th/@id and
td/@headers (<http://www.w3.org/TR/html4/struct/tables.html#h-11.4.1>).

Signature

Johannes Koch
In te domine speravi; non confundar in aeternum.
                            (Te Deum, 4th cent.)

Nik Coughlin - 29 Jul 2008 23:13 GMT
>I am trying to create a Zebra table where each Zebra "Strip" consists of
>two rows.

No need to set the classes on all the <tr>s, just the odd ones is enough.
Style the <td>s not the <tr>s.

<table class="zebra">
 <tr class="light">
   <td>Blah</td>
 </tr>
 <tr class="light">
   <td>Blah</td>
 </tr>
 <tr>
   <td>Blah</td>
 </tr>
 <tr>
   <td>Blah</td>
 </tr>
</table>

.zebra td {
 background-color: #CCFFFF;
}

.zebra .light td {
background-color: #00FFFF;
}
dorayme - 30 Jul 2008 00:45 GMT
> >I am trying to create a Zebra table where each Zebra "Strip" consists of
> >two rows.
>
> No need to set the classes on all the <tr>s, just the odd ones is enough.
> Style the <td>s not the <tr>s.

...

As Nick shows, it is easy enough to implement with just css.
Depending on the nature of your table - how much would be lost if there
were no stripes if js were disabled or unavailable in rare cases - you
might also consider a javascript solution. It saves a lot of bother if
the table is big and changes a lot or if it is generated via php from
csv files on the server.

There is an example of this at

<http://khs.org.au/historian_database/tz.html> and the js at

<http://khs.org.au/historian_database/table_row_stripe.js>

You would need to adapt to your two rows at a time requirements.

Signature

dorayme

Bruce A. Julseth - 30 Jul 2008 03:01 GMT
>> >I am trying to create a Zebra table where each Zebra "Strip" consists of
>> >two rows.
[quoted text clipped - 18 lines]
>
> You would need to adapt to your two rows at a time requirements.

The <tbody> solutions does exactly what I want... BUT, I do have frequent
changes which make updating the table a 'bear!'  So the JS suggestion is
welcomed. I had read about it somewhere. Thank to pointing me to an example.

Bruce
dorayme - 30 Jul 2008 03:39 GMT
> "dorayme" <doraymeRidThis@optusnet.com.au> wrote in message

> > You would need to adapt to your two rows at a time requirements.

> I do have frequent
> changes which make updating the table a 'bear!'  So the JS suggestion is
> welcomed. I had read about it somewhere. Thank to pointing me to an example.

If you have frequent changes, you might consider letting some PHP build
your table from a simple csv file (which is just a text file that has
the data with commas after each item, row by row to correspond to tr).
Easier to maintain.

You make the HTML file with a bit of php in place of the table. Put it
on the server along with a plain text file .csv. I do this now and then
and it is quite a time saver. It is especially decent in that it lets a
client prepare the spreadsheet and export to csv format. And you, the
webmaster, simply upload the csv file (or you can get the client to do
this...  but it is nice to keep a 'professional' eye on things, one must
be wary of giving clients too much power. They can get ideas that they
can do without you and then how do you pay advance tax bills?)

Signature

dorayme

Bruce A. Julseth - 31 Jul 2008 20:24 GMT
>> "dorayme" <doraymeRidThis@optusnet.com.au> wrote in message
>
[quoted text clipped - 18 lines]
> be wary of giving clients too much power. They can get ideas that they
> can do without you and then how do you pay advance tax bills?)

Thanks for the suggestion. I'll take a look at doing just that.

Bruce
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.