views:

545

answers:

2

Is there any way to make the header align towards right?
Tested in Internet Explorer 7 only.

<html>
    <style type="text/css">
        th {
            text-align: left;
        }
    </style>
<body>
    <table width="100%" border="1">
        <thead>
            <tr>
                <th style="width: 250px;">Tag
                <th style="width: 100px; text-align: right;">Duration
            </tr>
        </thead>
        <tbody>
            <tr>
                <td > one
                <td> two
            </tr>
        </tbody>
    </table>
</body>
</html>
+1  A: 

You aren't closing your TH tags (or your TD tags for that matter). Fix below:

<table width="100%" border="1">
        <thead>
            <tr>
                <th style="width: 250px;">Tag</th>
                <th style="width: 100px; text-align: right;">Duration</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td> one </td>
                <td> two </td>
            </tr>
        </tbody>
    </table>
Andy Baird
its not working :(
Amit
+1  A: 

First, close your tags. You have a lot of invalid HTML here. Second, you're mixing the table width (100%) as a percentage and the cell widths (250px, 100px) as pixel widths. These two are not compatible. Choose either one or the other and keep it consistent throughout your table.

<table style="width:350px" border="1">
    <thead>
        <tr>
            <th style="width:250px;">Tag</th>
            <th style="width:100px; text-align:right;">Duration</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>one</td>
            <td>two</td>
        </tr>
    </tbody>
</table>
Jim H.