Right aligning one column and left aligning the other, within one table

smurf picture smurf · Sep 2, 2011 · Viewed 30.3k times · Source

I have created a html table with 2 columns. I want the first column containing text to be right aligned, but i want the second column to stay left aligned as it contains check boxes. For presentation it would look, but ive no idea. I have tried creating a td class="column1" then text-align: right; in the CSS but no luck.

Any ideas would be greatly appreciated.

HTML

<td class="column1">Retrieve Logs:</td>
<td class="column2"><input type=checkbox name="getcamlogs" checked="checked"></td>

CSS

td.column1 {
   text-align: right;
}

Answer

Graeme Leighfield picture Graeme Leighfield · Sep 2, 2011

Here you go, this should work :)

<style>
    #mytable {width:500px; margin:0 auto;}
    #mytable td {width:250px;}
    #mytable .left {text-align:right; background:#333;}
    #mytable .right {text-align:left; background:#666;}
</style>

<table id="mytable">
    <tr>
        <td class="left">1</td>
        <td class="right">2</td>
    </tr>   
</table>