471,582 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

Alternative color in table row by css

12
Hi All,

I want to ask is any method to define one class of css to make the table with alternative color with row of table. (without using javascript or server side language)

For example :
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="bg">&nbsp;</td>
</tr>
<tr>
<td class="bg">&nbsp;</td>
</tr>
<tr>
<td class="bg">&nbsp;</td>
</tr>
<tr>
<td class="bg">&nbsp;</td>
</tr>
</table>


Thanks and Regards,
stepby
Aug 29 '07 #1
1 4116
phvfl
173 Expert 100+
Hi,

The easiest way to do this would be to add a class to alternate rows, for example:
[HTML]
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="bg">&nbsp;</td>
</tr>
<tr class="alt">
<td class="bg">&nbsp;</td>
</tr>
<tr>
<td class="bg">&nbsp;</td>
</tr>
<tr class="alt">
<td class="bg">&nbsp;</td>
</tr>
</table>
[/HTML]

Expand|Select|Wrap|Line Numbers
  1. .alt{background-color:#FF0000;}
  2.  
This example would turn the background colour of alternate rows red, assuming that the bg class did not also set the background colour
Aug 29 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

99 posts views Thread by Paul McGuire | last post: by
20 posts views Thread by Tammy | last post: by
3 posts views Thread by Billy | last post: by
15 posts views Thread by Steffen Ramlow | last post: by
2 posts views Thread by chrisoftoday | last post: by
5 posts views Thread by Phuff | last post: by
reply views Thread by XIAOLAOHU | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.