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
removed dead ImageShack link
To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.
CSS Demo: vertical-alignThe vertical-align property can be used in two contexts: To vertically align an inline element's box inside its containing line box. For example, it could be used to vertically position an image in a line of text. To vertically align the content of a cell in a table.
Using the Line-Height Property In most cases, you can also center text vertically in a div by setting the line-height property with a value that is equal to the container element's height.
Not so elegant, but works. Create one-cell table. Only table has cross-browser vertical-align.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With