Forum Moderators: not2easy

Message Too Old, No Replies

table alignment

         

becks3636

9:24 am on Feb 25, 2009 (gmt 0)

10+ Year Member



Hi, does anyone know the css code so I can align a table in the centre of a html page? thanks...

swa66

9:30 am on Feb 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld! [webmasterworld.com]

I'm afraid we need a bit more info on the goal as well as the environment.

center of the html page: horizontally, vertically, both ?
html page: the screen or the page ?
the context: what elements are parents of your table and do any of them have position or explicitly set height and/or width?
the table: does it have a set size ?

...

becks3636

10:18 am on Feb 25, 2009 (gmt 0)

10+ Year Member



Hi,

Its a set width table which needs to look central in the browser and has some text and images inside. It needs to be aligned centrally and vertically. thanks...

tangor

10:59 am on Feb 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<table align="center"></table> is the old way. Still works. Or

<div align="center"><table></table></div>

As for vertical alignment... let me know how you make out. :)

sgietz

2:10 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



Well, wanting to center it in both direction is the monkey wrench here. This will be difficult, since you won't know the height of the table (or do you?). If you know the dimensions, you can set top and left positioning to 50% and top and left margins to the "negative" values of "half" the width and height.

Or dirty trick #47:

<table width="100%">
<tr>
<td align="center" valign="middle">

<table width=desired width>
content here
</table>

</td>
</tr>
</table>

Ahh, so easy, but you will have to endure the wrath of many CSS and HTML purists. :)

rocknbil

4:05 pm on Feb 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard becks3636!

Vertical positioning is always going to be problematic. Horizontal, easy:

<table style="margin:auto;border:1px solid #000000;">
<tr><td>some content</td></tr>
</table>

Dead Centre Positioning [wpdfd.com] from an old WebmasterWorld post.