Results 1 to 7 of 7

Thread: Centering a table

  1. #1
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Centering a table

    Hi.
    My current code is
    HTML Code:
    <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

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try:
    Code:
    <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>
    Jeremy | jfein.net

  3. #3
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Cool thanks works brilliantly

  4. #4
    Join Date
    Dec 2008
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    I would just use align tags but i guess margin: auto; or margin: 0 auto; would do exactly the same:

    Code:
    <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>

  5. #5
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    align is a deprecated attribute and should not be used, margin: 0 auto; is semantic. Using tables for layout is also bad practice.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    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.
    Jeremy | jfein.net

  7. #7
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Quote Originally Posted by Nile View Post
    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/
    and of course read this article if you haven't already: 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •