Jump to content

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


spence911
Go to solution Solved by Barand,

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>
Edited by spence911
Link to comment
Share on other sites

  • Solution

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.