left-right-center aligned

M

mre

Hi

Is it possible to have each column cell in a table to be left-aligned
with each other, but also right-aligned with the cell based on the
longest content.

So a table like...

<table>
<tr><td>aaa</td><td>bbb</td></tr>
<tr><td>aaaaaa</td><td>bbb</td></tr>
<tr><td>aaaaa</td><td>bbb</td></tr>
</table>

....could be output like...

______Left align
|
[[ aaa ][bbb ]]
[[ aaaaaa][bbb ]]
[[ aaaaa ][bbb ]]
|____|
|___Right align as a group
to the center of the table

....at the moment, the closest I have is right-aligning the TD, and in
that, having a left-aligned SPAN where I set the em width manually -
but as the page is generated dynamically, I can only really guess what
that'll be.


Thank you for any help,
Regards,
MRe
 
E

Els

mre said:
Hi

Is it possible to have each column cell in a table to be
left-aligned
with each other, but also right-aligned with the cell based
on the longest content.

So a table like...

<table>
<tr><td>aaa</td><td>bbb</td></tr>
<tr><td>aaaaaa</td><td>bbb</td></tr>
<tr><td>aaaaa</td><td>bbb</td></tr>
</table>

...could be output like...

______Left align
|
[[ aaa ][bbb ]]
[[ aaaaaa][bbb ]]
[[ aaaaa ][bbb ]]
|____|
|___Right align as a group
to the center of the table

...at the moment, the closest I have is right-aligning the
TD, and in that, having a left-aligned SPAN where I set the
em width manually - but as the page is generated
dynamically, I can only really guess what that'll be.

Just make sure the cell width is small enough to have the
largest content touch the right side of the column, and then
left-align with a left padding?
 
M

MRe

mre said:
Is it possible to have each column cell in a table to be
left-aligned
with each other, but also right-aligned with the cell based

Hi Els, thank you for the response.

<oops>
Sorry, I should also have mentioned in my previous post that my
table width was 100% and columns were 50% each
</oops>

I tried playing around with different ideas based on your reply, and
the best I came up with this (below) - are there better ways? I don't
know how to make something small enough to fit the largest content -
how's it done? - or was that response based on the fact that I'm an
idiot and forgot to mention the width of my table/cells?

<table style="width: 100%;">
<tr>
<td></td>
<td width="1px"><div style="white-space: nowrap;">abc def</div></td>
<td width="50%">fdsafd</td>
</tr>
<tr>
<td></td>
<td width="1px"><div style="white-space: nowrap;">a b c</div></td>
<td width="50%">fdaf</td></tr>
</table>

Thank you for your help :)
Regards,
MRe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top