Click to See Complete Forum and Search --> : Tables and centering


Semprise
02-19-2008, 01:34 PM
I am trying to create a side column with some links on my page. I do not want to use frames.
When I use tables, it works ok, but I want to center some text in the second (large) column so that it is in the center of the screen.
When I try to align the text, it centers itself relative to the column which is not what I want.
Any tips on how to get the text centered when using a side bar?
Thanks.

yamaharuss
02-19-2008, 02:49 PM
You need to define a width to your table cells, otherwise the table will only be as wide as the content within. Although, best to get rid of tables and do everything CSS.

Semprise
02-19-2008, 03:00 PM
Thanks for replying.
I would like to use HTML, since the rest of the code I am working with uses it.
The width has been defined. For example:

<TABLE border="1">
<TR><TD width="200">ABC<TD width="900"><center>113212</center>
</TABLE>

I want the centered part to be in the center of the screen, not in the center of its column.
Maybe if there is a way of putting text slightly off center, like (center - x spaces ) that would work as well.

yamaharuss
02-19-2008, 05:09 PM
<TABLE border="1">
<TR><TD width="200">ABC<TD width="900"><center>113212</center>
</TABLE>

I want the centered part to be in the center of the screen, not in the center of its column.
Maybe if there is a way of putting text slightly off center, like (center - x spaces ) that would work as well.


CSS is not exactly a whole different programming language. Well, it is and it isn't. It's made to work hand-hand with and enable you to do more with your HTML.

What you're asking to do is impossible. Can't be done. You can't have a 200px wide column left of a 900px column and center any content relative to the entire table. Using spaces will not center your content. You might get lucky and get it to look centered on a few screens but how would you account for everyone having different screen resolutions and window sizes?

Not only that, your table code is not proper. You're missing two closing TD tags and a closing TR tag.

The only solution to your problem is using CSS. If you're not willing to then you will need to either redesign your table or place your content differently.

yamaharuss
02-19-2008, 05:18 PM
OK, after thinking.... although it's still a bad idea to be designing in tables.....

This can be done using percentages

Mind you, this code may work (for now) but it is NOT standards compliant

<TABLE border="1" height="100%" width="100%">
<TR>
<TD width="20%">ABC</TD>
<TD width="60%" align="center" valign="center">my content</TD>
<TD width="20%">&nbsp;</TD>
</TR>
</TABLE>

Disclaimer: The code provided is intended for entertainment purposes only. Prolonged use may be harmful to your reputation. Women should not ingest tables or use the "align" tag during pregnancy. Please do not try this at home.

Frank62
02-20-2008, 10:47 AM
Y,

As long as you replace valign="center" with valign="middle", and you ignore the fundamentalistic position of the W3C regarding height declarations, it validates perfectly well as HTML 4 Transitional.

Semprise
02-20-2008, 12:31 PM
OK, it looks like I'll be using CSS after all. Thanks for the help.