Wiki tables column alignment

Soldato
Joined
6 Mar 2008
Posts
10,079
Location
Stoke area
Hi all,

I've a wiki table with around 40-50 rows and 8 columns.

I want the left column left aligned, but the rest center aligned.

However I can't seem to figure out how to apply alignment to an entire row, only to individual cells, rows or the table as a whole.

Anyone know how?
 
This is where the CSS selector ':first-child' comes in handy.

Using something like the css below will align the text in the first tr element to the left. The rest will remain centered.
Code:
      table {
        text-align:center;
      }
      table tr:first-child {
        text-align:left;
      }

However, as with most useful things, it doesn't work in older versions of IE.
To fix this, I suggest adding a class to the first tr element like so:

Code:
<table>
  <tr class="leftAlign">
    <td>
      First Row
    </td>
    <td>
      First Row
    </td>
  </tr>
  <tr>
    <td>
      Second Row
    </td>
    <td>
      Second Row
    </td>
  </tr>
  <tr>
    <td>
      Third Row
    </td>
    <td>
      Third Row
    </td>
  </tr>
</table>

Then, in your stylesheet, add this:
Code:
.leftAlign {
    text-align:left;
}
 
Back
Top Bottom