Link to home
Start Free TrialLog in
Avatar of ARACK04
ARACK04

asked on

custom formating of <table>

In excel there is a way to automatically put a $ at the very left of each cell, and then have whatever number you put in go right aligned in the cell.  Is there any way to do that in an html table?  Thanks!

Avatar of Batalf
Batalf
Flag of United States of America image

You could assign styles to a col tag.

<table border="1" width="500">
      <col style="text-align:right">
      <col>
      <tr>
            <td><p>Data</td>
            <td><p>Data</td>
      </TR>
      <tr>
            <td><p>Data</td>
            <td><p>Data</td>
      </TR>
</table>
or you could just add style to a single cell

<style type="text/css">
.right{text-align:right;}
</style>
<table border="1" width="500">
     <tr>
          <td class="right"><p>Data</td>
          <td><p>Data</td>
     </TR>
     <tr>
          <td><p>Data</td>
          <td><p>Data</td>
     </TR>
</table>

or

<td style="text-align:right">Right aligned</td>

or yet another way

<td align="right"><p>Data</td>
Avatar of ARACK04
ARACK04

ASKER

I'm trying to get a $  at the left end of my table cell and my data at the right end of it.

I created a css class for <p> setting text-align to left, and a css class for <td> setting it to right and said:

<tr><td colspan='1' class="right"><p class='left'>$</p>100.00</td></tr>

As expected though, it put a <br> after the <p> tag.  I tried setting colspan='1' on the <td> but it ignored it and put the newline anyway.  I'm really close.  I've got the $ on the left and the data on the right, I just need to get it on the same line.
The easiest way is to add a own column for the $

<table border="0">
<tr>
      <td width="10"><p>$</TD>
      <td class="right"><p>100.00</td>
</tr>
</table>
ASKER CERTIFIED SOLUTION
Avatar of Batalf
Batalf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial