SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Location
    Somewhere
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Center Alignment

    How do center align a div using css? My layout does not use any tables.

  2. #2
    Typo Negative brokenvoice's Avatar
    Join Date
    Dec 2001
    Location
    Scotland
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without seeing your code, I'd guess you'd have to put it inside another div with its text-align set to center:
    Code:
    #container
    {
        text-align : center;
    }
    
    <div id="container">
        <div>
            [YOUR CONTENT HERE]
        </div>
    </div>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Location
    Somewhere
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I want the content of the site to center aligned.

  4. #4
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do You Mean Like This?

    Just use the text-align: center; that bv mentioned, but you don't need to use the second div.

    If you want to place a fixed with table in the center of the page, then margin: auto; would be the correct syntax. You don't need to double up your <DIV>s for that, ether. Unfortunately, I don't believe that IE5 does that correctly, but the content will just be on the left instead of the center. :-)

    ~~Hope This Helps

  5. #5
    Typo Negative brokenvoice's Avatar
    Join Date
    Dec 2001
    Location
    Scotland
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Ian Glass
    ...I don't believe that IE5 does that correctly, but the content will just be on the left instead of the center.
    IE6 gets it wrong depending on the DOCTYPE too, hence the 2 div kludge

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Location
    Somewhere
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


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
  •