Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing table cells from right to left

I make a table and want the first cell to start from right instead of from left as default. I tried changing the float attribute in CSS but it doesn't seem to help. Here is the code:

<table border="0" width="100%" cellspacing="0" align="center" class="result_table">
    <tr align="right">
    <th bgcolor="#cccccc" align="right">1</th>
    <th bgcolor="#cccccc" size="17">2</th>
    <th bgcolor="#cccccc">3</th>
    <th bgcolor="#cccccc">4</th>
    </tr>

</table>

<style>
    table.result_table {
        float:right;
    }
</style>

Can anyone suggest a way to change the float of this table?

like image 526
antonpuz Avatar asked Mar 08 '13 12:03

antonpuz


People also ask

How do you make a table left to right?

To align the table, select the table and click one of the other options: Center or Left Align. Using these three options you can quickly and easily align your table to the left, center, or right of the page. You can also use the Table Properties option to align a table.

How do you make a table left to right in HTML?

The table alignment in HTML can be done using align attribute. The align attribute can take the values left, right, or center. To align the content of the table we can use text-align or vertical-align attribute.


2 Answers

There is a much easier way. You can add direction="rtl" to the table.

<table dir="rtl">
     ...
</table>
like image 68
eylay Avatar answered Oct 28 '22 02:10

eylay


As suggested in comments, you can set directionality to right-to-left (RTL). However, unless your table content is in a right-to-left language, you should additionally set the directionality in table content elements to left-to-right. Otherwise, they inherit RTL directionality, which will cause surprises in many situations, since the directionality also sets the overall text directionality. This will not affect normal text in a Western language, but it will affect e.g. content like “4 (5)”, which would appear as “(5) 4” with RTL directionality.

Thus, you should set

table.result_table {
  direction: rtl; }
table.result_table caption, table.result_table th, table.result_table td {
  direction: ltr; }
like image 42
Jukka K. Korpela Avatar answered Oct 28 '22 01:10

Jukka K. Korpela