tags:

views:

142

answers:

2

I need to center vertically multiple boxes with different heights.

I dont know the height of the boxes as they are variable texts.

How can I do this with CSS (without having to use td and valign). Tried display: table-cell but it seems not compatible with IE

The image below shows the design, the post-it is the browser window

alt text

+4  A: 

Not so elegant, but works. Create one-cell table. Only table has cross-browser vertical-align.

Dewfy
+1 sometimes you just have to http://giveupandusetables.com/
kemp
done it, in 3 mins
Victor P
@Victor P you are welcome
Dewfy
+2  A: 

Assuming you want the boxes to be fixed-width you can use the folling markup

<div class="vcontainer">
    <span>1<br/>2</span>
    <span>1<br/>2<br/>3<br/>4</span>
    <span>1<br/>2<br/>3</span>
</div>

with these styles

.vcontainer {
    text-align: center;
}

.vcontainer span {
    display: inline-block;
    width: 150px;
    vertical-align: middle;
}

The inline-block property works in most modern browsers.

Josef
This is basically the correct way to do things. However, if you change the three elements to `<span>` instead of `<div>` then you get compatibility with even IE6! For Firefox 2 (if necessary), you can add `display:-moz-inline-box`.
DisgruntledGoat
@DisgruntledGoat thanks, I edited that into my answer.
Josef