SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTML center tag does not center

    Hello! I know most web development folk would be horrified that I would ask a question about such shoddy deprecated code as this, but please help me out.

    Code:
    <html>
    <body>
    <table width="100%" align="right">
    <tr>
    <td align="right">
    Right1<br />
    Right2<br />
    Right3<br />
    Right4<br />
    Right5<br />
    </td>
    </tr>
    </table>
    <center>
    One<br />
    Two<br />
    Three<br />
    Four<br />
    Five<br />
    </center>
    </body>
    </html>
    Why does the content in the center tag appear on the left rather than the center like it should? And what is the simplest, least-intrusive way to fix it? I know putting in a DOCTYPE would fix it right up, but I really don't want to go messing around with existing production code.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    I'm truly horrified that you would ask a question about such shoddy deprecated code as this!

    Anyhow, some browsers will center that content—with or without the doctype (such as Firefox). What browser are you testing in?

    I guess you could continue with the pattern of the code you already have, and change it to this:

    Code:
    <table width="100%">
    <tr>
    <td align="center">
    One<br />
    Two<br />
    Three<br />
    Four<br />
    Five<br />
    </td>
    </tr>
    </table>
    or this

    Code:
    <html>
    <body>
    <table width="100%">
    <tr>
    <td align="right">
    Right1<br />
    Right2<br />
    Right3<br />
    Right4<br />
    Right5<br />
    </td>
    </tr>
    <tr>
    <td align="center">
    One<br />
    Two<br />
    Three<br />
    Four<br />
    Five<br />
    </td>
    </tr>
    </table>
    </body>
    </html>
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The text was not centered in I.E. 9, but you were correct: the text was centered in Firefox (and Chrome)

    Both of those solutions worked great. Thank you!


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
  •