Danpe
Danpe

Reputation: 19047

Right Align Table?

This code:

<table border="1">
    <tr>
        <th>a</th>
        <th>b</th>
        <th>c</th>
        <th>d</th>
    </tr>
</table>

http://jsfiddle.net/ca86D/ Generates:

a | b | c | d

How can I make it generate :

d | c | b | a

?

Without changing the order of the < th >

Upvotes: 2

Views: 161

Answers (4)

welldan97
welldan97

Reputation: 3076

You can add dir="rtl" attribute to table:

<table border="1" dir="rtl">
    <tr>
        <th>a</th>
        <th>b</th>
        <th>c</th>
        <th>d</th>
    </tr>
</table>

Demo: http://jsfiddle.net/74XHk/1/

(tried to add it to tr, that didn't work)

Upvotes: 4

Sotiris
Sotiris

Reputation: 40046

add in your css th {float:right}. This will reverse the sequence, because will start with first th which contains d and will float it at right, then the second and so on.

Demo: http://jsfiddle.net/ca86D/2/

Upvotes: 4

Jimmy Geers
Jimmy Geers

Reputation: 742

<table border="1">
    <tr>
        <th>d</th>
        <th>c</th>
        <th>b</th>
        <th>a</th>
    </tr>
</table>

Upvotes: 0

Ash Burlaczenko
Ash Burlaczenko

Reputation: 25435

Surely just

<table border="1">
     <tr>         
         <th>d</th>
         <th>c</th>
         <th>b</th>
         <th>a</th>
     </tr>
</table> 

Hope I didn't misunderstand your question.

Upvotes: 0

Related Questions