View Full Version : Centering a table
Hi.
My current code is
<table style="width: 66%" >
<tr>
<td class="style4">
<a href="http://au.youtube.com/user/bombardieraddict123" style="color:white" class="style5">
Bombardieraddict123</a></td>
</tr>
<tr>
<td style="background-color:white">More Information Will go here</td>
</tr>
</table>
This is obviously a table, inside a div. But the table is aligned to the left. I can't remember how to align it to the center, so you someone please help me out? Thanks :)
Try:
<table style="width: 66%; margin: 0 auto;">
<tr>
<td class="style4">
<a href="http://au.youtube.com/user/bombardieraddict123" style="color:white" class="style5">
Bombardieraddict123</a>
</td>
</tr>
<tr>
<td style="background-color:white">
More Information Will go here
</td>
</tr>
</table>
Cool thanks works brilliantly :D
saynogo9999
01-26-2009, 09:18 PM
I would just use align tags but i guess margin: auto; or margin: 0 auto; would do exactly the same:
<table align="center" style="width: 66%" >
<tr>
<td class="style4">
<a href="http://au.youtube.com/user/bombardieraddict123" style="color:white" class="style5">
Bombardieraddict123</a></td>
</tr>
<tr>
<td style="background-color:white">More Information Will go here</td>
</tr>
</table>
Snookerman
01-26-2009, 09:26 PM
align is a deprecated attribute (http://www.codehelp.co.uk/html/deprecated.html) and should not be used, margin: 0 auto; is semantic. Using tables for layout (http://hotdesign.com/seybold/everything.html) is also bad practice.
Using layouts isn't always bad, it can sometimes be very useful - you cannot be sure that he was using the table for a layout.
Snookerman
01-26-2009, 10:34 PM
Using layouts isn't always bad, it can sometimes be very useful
Tables for layout is bad, there are much better, easier, forward-compatible ways to achieve the same/better effect. Take a look at this tutorial:
http://nettuts.com/videos/screencasts/everything-you-know-is-wrong/ (http://nettuts.com/videos/screencasts/everything-you-know-is-wrong/)
and of course read this article if you haven't already: http://www.hotdesign.com/seybold/everything.html (http://www.hotdesign.com/seybold/everything.html)
you cannot be sure that he was using the table for a layout.
Yes I can! Hehe, of course not but good advice doesn't hurt anyone.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.