Jump to content

What does <tr class="alt"> mean when creating an HTML table


spence911

Recommended Posts

alt is the name of the CSS class definition. Check your CSS stylesheet to see what styles are applied for that class.

 

This is a very simple HTML table. There is no CSS stylesheet.

<table cell spacing = "0" border = "5" style = "width: 20 em; border: 1px solid #567;">
<tr>
<th>Sequence #</th>
<th>Value</th>
</tr>
<tr>
<td>F<sub>0</sub></td>
<td>0</td>
</tr>
<tr class = "alt">
<td>F<sub>1</sub></td>
<td>1</td>
</tr>
</table>

you need to have defined the "alt" class in the styles eg

<html>
<head>
<style type="text/css">
    table {
        border-collapse: collapse;
    }
    tr {
        background-color: #CCCCCC;
    }
    tr.alt {
        background-color: #C0FFC0;
    }
</style>
</head>
<body>
    <table border="1" cellpadding="4" cellspacing="0">
    <?php
        $c = 'A';
        for ($row=0; $row<6; $row++) {
            $cls = $row%2 ? '' : "class='alt'";
            echo "<tr $cls>";
            for ($col=0; $col<3; $col++, $c++) {
                echo "<td>$c</td>";
            }
            echo "</tr>\n";
        }
    ?>
    </table>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.