Simon Lenz
Simon Lenz

Reputation: 2812

HTML table column align right

I have a table with 3 columns. I want that the third column is aligned to the right of the upper element and the other 2 columns to the left, like this:

(left column) (middle column)                                      (right column)

Is there a way to do this via CSS or something?

Upvotes: 18

Views: 59964

Answers (3)

pleasedontbelong
pleasedontbelong

Reputation: 20102

There are a few ways to do what you want. The most basic is to change the alignment directly in the tag

<td align='left'>data1</td><td align='right'>data1</td><td align='left'>data1</td>
<td align='left'>data2</td><td align='right'>data2</td><td align='left'>data2</td>
....

If you need to change something else (CSS style) you could create a class like .firstColumn and .secondColumn on each <td>.

I tried to change directly the column, but that doesn't work (HTML table colgroup element is not working).

Upvotes: 5

user2569050
user2569050

Reputation: 455

<td style="text-align:right;">data1</td>

Upvotes: 6

Vinay B R
Vinay B R

Reputation: 8421

Use width:100% on the table and the middle column.

Upvotes: 25

Related Questions