SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Centered layout using CSS

    I was wondering if there is possibility to make centered fixed width layout using CSS as it was with tables.
    For example, using tables it looks like this:
    <table ... width="500" align="canter">
    ...
    </table>

    As i remember, SP's CSS book doesnt have answer for that.

    Thanks for helping,
    Sander

  2. #2
    SitePoint Member
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe margin:auto for the table would be the appropiate way to do it. But guess what? IE doesn't support it. However, as IEs moronic rendering for text-align:center includes tables, you can do something like this:
    Code:
    <body style="text-align:center"> 
    <table style="width:400px; background-color:#000; margin:auto"><tr><td></td></tr></table>
    The margin:auto caters for correct CSS support, whilst text-align:center in the body caters for moronic IE support.
    PersonalTechNews.com
    Quick loading tech headlines from user-selected sources.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for answer, but that not what i wanted. Maybe my bad. Let me explane more. This table example is there that i know how to put page content center of page using tables but now i want to achieve same thing using only CSS, no tables at all.

  4. #4
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just put your whole site in a container div and use the same trick
    Code:
    body {text-align:center;} /* to fool IE */
    div#container {
        margin:auto; /* for 'real browsers' */
        text-align:left; /* because of the IE hack above */
        width:400px;
    }
    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac


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
  •