Alternative color in table row by css

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stepby
    New Member
    • Aug 2007
    • 12

    Alternative color in table row by css

    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">&nbs p;</td>
    </tr>
    <tr>
    <td class="bg">&nbs p;</td>
    </tr>
    <tr>
    <td class="bg">&nbs p;</td>
    </tr>
    <tr>
    <td class="bg">&nbs p;</td>
    </tr>
    </table>


    Thanks and Regards,
    stepby
  • phvfl
    Recognized Expert New Member
    • Aug 2007
    • 173

    #2
    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">&nbs p;</td>
    </tr>
    <tr class="alt">
    <td class="bg">&nbs p;</td>
    </tr>
    <tr>
    <td class="bg">&nbs p;</td>
    </tr>
    <tr class="alt">
    <td class="bg">&nbs p;</td>
    </tr>
    </table>
    [/HTML]

    [CODE=css]
    .alt{background-color:#FF0000;}
    [/CODE]

    This example would turn the background colour of alternate rows red, assuming that the bg class did not also set the background colour

    Comment

    Working...