Center multiple divs inside another div

Discussion in 'CSS' started by Abh, May 1, 2010.

  1. #1
    I have something like this:
    
    <div id="main">
    <div class="tobecentered"></div>
    <div class="tobecentered"></div>
    </div>
    
    Code (markup):
    and i need them to position themselves horizontally like in the pic:
    [​IMG]

    Now, if i float them, they stick to the margin of #main. If i text-align center them, they position themselves one under the other.

    Any ideas?
     
    Abh, May 1, 2010 IP
  2. Abh

    Abh Active Member

    Messages:
    162
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #2
    solved. i put them inside another fixed width div and centered that one while left floating them.
     
    Abh, May 1, 2010 IP
  3. pmek

    pmek Guest

    Messages:
    101
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, or you could have added padding to the main div, or margins to the centered ones. It depends if the main div is meant to span the width of a users browser though...
     
    pmek, May 7, 2010 IP