How can I vertically align two floated divs?

css, html

Solution

here is the online demo of the solution you needed

it was made with this html:

<div id='parent'>
    <div id='left-box' class='child'>Some text</div>
    <div id='right-box' class='child'>Details</div>    
</div>

and this css:

#parent {
    position: relative;

    /* decoration */
    width: 500px;
    height: 200px;
    background-color: #ddd;
}

.child {
    position: absolute;
    top: 50%;
    height: 70px;
    /* if text is one-line, line-height equal to height set text to the middle */
    line-height: 70px;
    /* margin-top is negative 1/2 of height */
    margin-top: -35px;

    /* decoration */
    width: 200px;
    text-align: center;
    background-color: #dfd;
}​

#left-box { left: 0; }
#right-box { right: 0; }

Problem

I have two divs inside a container div. One need to float left the other float right. They also both need to be vertically centered inside their parent. How can I achieve this? ``` <div id='parent'> <div id='left-box' class='child'>Some text</div> <div id='right-box' class='child'>Details</div> </div> ``` If no float is applied to either they vertically align to the middle with this css ``` .child{ display:inline-block; vertical-align:middle; } ``` However adding `#right-box{ float: right; }` causes the children to lose their vertical alignment. What am I doing wrong? Thanks guys

Original source