Possible Duplicate:
Vertically centering a div inside another div
I'm trying to vertically align one div inside another. It is also centered, but that I seem to be able to get to work. The inside div has a explicit width, which I need to be able to do. The height should be determined by the amount of content. I've tried various solutions I've seen on stackoverflow, but none of them seem to quite work right. A few of them seem to work if there is no explicit width on the inner div, or if the horizontal centering is not necessary. This question is different from others in that those do not have explicit widths, or when they do, the solutions include static padding, or javascript which calculates padding. I wish to avoid this.
html:
<div class="outer">
<div class="inner">
//some stuff<br/>
</div>
</div>
css:
.outer {
width: 100%;
height: 96px;
position:relative;
border:1px black solid;
background-color: black;
}
.inner {
width:900px;
height: 40px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border: 1px red solid;
vertical-align: middle;
background-color: white;
}
Update, this was solved by Passerby below. There are indeed many people asking very similar questions, however I think there is enough different here. The answer was also not the same as any of the other answers I have seen.