JavaScript and client side scripting.
Moderator: General Moderators
gavinbsocom
Forum Commoner
Posts: 71 Joined: Tue Sep 30, 2003 9:51 pm
Post
by gavinbsocom » Fri Dec 05, 2003 4:50 pm
How would I align a table in css? I dont want to do it in the html document itself? I know you can use
Code: Select all
table.head
{
align: center; ???
}
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Dec 08, 2003 3:11 am
If memory serves, one way of aligning a table which works in both IE and Gecko browsers is to add a little hack for IE, a div tag with an text-align: center style:
Code: Select all
<div style="text-align: center">
<table style="margin: 0 auto;>
<!-- more table tags -->
</table>
</div>
Mac
Fredix
Forum Contributor
Posts: 101 Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:
Post
by Fredix » Sun Dec 14, 2003 10:09 am
For me
Code: Select all
table
{
maring-left:auto;
margin-right:auto;
}
alsways worked out as long as table is not positioned absolutely.
This method is also W3C correct.
Skyzyx
Forum Commoner
Posts: 42 Joined: Fri Feb 14, 2003 1:53 am
Location: San Jose, CA
Post
by Skyzyx » Tue Dec 23, 2003 7:51 pm
Setting margin-left:auto and margin-right:auto only works when the width is explicitly set.
Code: Select all
table {
margin:0 auto 0 auto;
width:500px;
}
Also, you can center an element by making a container, and setting text-align:center to that container.
Code: Select all
<div style="text-align:center;">
<table>
<tr>
...
</tr>
</table>
</div>