SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: HTML center tag does not center

  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    21
    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
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    20,303
    Mentioned
    225 Post(s)
    Tagged
    3 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

    Try your hand at the new JavaScript Challenge!

    If you don't like getting your feet stuck in a bog, avoid Twitter BootsTrap.

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    21
    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
  •