SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    England
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Centering A Div Without Centering The Contents

    Hi,

    I have a new design I'm just finishing up on http://www.get2sammyb.co.uk but I have a small error in my design. The flaw is that the main box containing all the content should be in the centre - however I ahve tried to do this in a number have way but it has always resulted in the text inside the content box also being centred - which is not what I want.

    How can I solve this problem?

    Thanks in advance.

    Sammy.

  2. #2
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just add the following

    Code:
    #container {
        width: 800px;
        color: #333333;
        background-color: #FFFFFF;
        border: 1px solid #000000;
        margin: 0 auto;
    }

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    England
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What a lovely piece of code I didn't know existed. Thanks so much csswiz

  4. #4
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you need to support IE5.5 then you'll also need text-align: center; on the body and then you can reset it to left if required on the container.

    I don't tend to go to that extent in IE5.5 though unless it's requested by a client as I'm sure the 0.01% of users still using it won't complain too much that the page is left aligned instead of centered but the option is there if you want to do it.

    Personally I just apply the width and margin to the body itself so that everything within it is centered (again though this doesn't work in IE5.5).


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
  •