Positioning Div's

Discussion in 'HTML & Website Design' started by gbabula, Nov 8, 2007.

  1. #1
    I have a div that contains three divs inside it. If I wanted to center the three divs inside my one div, how would I do that?

    I have been playing around with this for 2-3 hours and I cant figure it out, hope you guys can help me out..

    
    <div class="block2">	
    
    <div id="block2divone">
    <h2>Box1</h2>
    <p>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam blandit elementum lorem. Suspendisse potenti. Nunc tellus dolor, 
    hendrerit nec, elementum faucibus, egestas mollis, dolor. Duis at erat. Nulla facilisi. Vestibulum leo massa, sodales ut, suscipit 
    quis, rutrum vel, risus. Praesent ac nisl ac sapien porta semper. Duis pellentesque consequat velit. 
    </p>
    </div>
    
    <div id="block2divtwo">
    <h2>Box2</h2>
    <p>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam blandit elementum lorem. Suspendisse potenti. Nunc tellus dolor, 
    hendrerit nec, elementum faucibus, egestas mollis, dolor. Duis at erat. Nulla facilisi. Vestibulum leo massa, sodales ut, suscipit 
    quis, rutrum vel, risus. Praesent ac nisl ac sapien porta semper. Duis pellentesque consequat velit.
    </p>
    </div>
    
    <div id="block2divthree">
    <h2>Box3</h2>
    <p>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam blandit elementum lorem. Suspendisse potenti. Nunc tellus dolor, 
    hendrerit nec, elementum faucibus, egestas mollis, dolor. Duis at erat. Nulla facilisi. Vestibulum leo massa, sodales ut, suscipit 
    quis, rutrum vel, risus. Praesent ac nisl ac sapien porta semper. Duis pellentesque consequat velit. 
    </p>
    </div>
    
    </div>
    
    
    HTML:
    Here is my CSS:

    
    div.block2 {
    background: #182752 url(images/spacer.gif) repeat-y 50% 0;
    color: #fff;
    margin: 0;
    padding: 5px 0;
    text-align: center;
    }
    
    #block2divone {
    width: 220px;
    float:left;
    border: 1px solid #97c93c;
    margin: 6px 8px 0 8px;
    padding: 10px;
    text-align: center;
    }
    
    #block2divtwo {
    width:220px;
    float:left;
    border:1px solid #97c93c;
    margin:6px 8px 0 0px;
    padding:10px;
    text-align: center;
    }
    
    #block2divthree {
    width:220px;
    float:left;
    border:1px solid #97c93c;
    margin:6px 8px 0 0px;
    padding:10px;	
    text-align: center;
    }
    
    Code (markup):
     
    gbabula, Nov 8, 2007 IP
  2. gbabula

    gbabula Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can someone help me out please?
     
    gbabula, Nov 8, 2007 IP
  3. NoobieDoobieDo

    NoobieDoobieDo Peon

    Messages:
    1,456
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perhaps place a <center> after the 1st div opens but before the 3 containers ?
     
    NoobieDoobieDo, Nov 8, 2007 IP
  4. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #4
    margin:0 auto; on a container element (and a width to see the effect)
     
    soulscratch, Nov 8, 2007 IP