Centering with CSS

Discussion in 'CSS' started by d0cpaul, May 5, 2010.

  1. #1
    I'm trying to center my blog in the middle of the screen but i'm not quite sure what I just adjust... I've been messing with the margin in the #wrap but it keeps pushing my blog to the right... Any ideas? You'll see what I mean when you go to my site..

    Here is my site.
    http://www.loansafe.org/you-walk-away-calculator
     
    d0cpaul, May 5, 2010 IP
  2. Paweł

    Paweł Active Member

    Messages:
    210
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    Change to:
     
    Paweł, May 5, 2010 IP
  3. Wtfuxbbq

    Wtfuxbbq Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    All you need to do is change the width on body to 100% and its margins to 0px

    You should also change the margin of #wrap to margin:0px auto; to save 4 characters of space.
    Although you can leave it at margin: 0px auto 0px; as it does exactly the same thing
     
    Wtfuxbbq, May 5, 2010 IP
  4. ampg-it

    ampg-it Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you could also specify the width of your main content, so it looks something like this.
           width: 940px;
    	margin-right: auto;
    	margin-left: auto;
    
    Code (markup):
     
    ampg-it, May 6, 2010 IP
  5. digital29

    digital29 Peon

    Messages:
    462
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you want centering in Internet explorer too, do this in addition of the last reply
    body { text-align: center; }
    #wrap { text-align: left; }
     
    digital29, May 6, 2010 IP
  6. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #6
    I would normally use the following to center:

     
    mfscripts, May 6, 2010 IP
  7. marc21

    marc21 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    text-align:center;
    margin: 0 auto;
     
    marc21, May 14, 2010 IP
  8. d0cpaul

    d0cpaul Member

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #8
    Thanks a lot =]
     
    d0cpaul, May 14, 2010 IP
  9. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That only applies for IE6 in quirks mode because it doesn't understand auto. Is that right? :confused:
    Can we drop it if we have a valid doctype to keep IE6 in standards mode?
     
    Cash Nebula, May 15, 2010 IP
  10. zaiful79

    zaiful79 Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #10
    I was just learning css, so can not love advice.
    regards
     
    zaiful79, May 16, 2010 IP
  11. xtek

    xtek Well-Known Member

    Messages:
    943
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #11
    Your centering best friend: "margin: 0 auto;"
     
    xtek, May 18, 2010 IP
  12. bobsmithmoodeyit

    bobsmithmoodeyit Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    margin: 0 auto;
     
    bobsmithmoodeyit, May 19, 2010 IP
  13. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #13
    That is for IE5 and for IE6 in quirks mode. Since IE5 was superseded 9 years ago, and since you should never, ever trigger quirks mode, quit using a buggy, incorrect method. No other browser would be centered by that silliness.

    cheers,

    gary
     
    kk5st, May 19, 2010 IP
  14. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #14
    Yes.

    cheers,

    gary
     
    kk5st, May 19, 2010 IP