This question resulted from a fix suggested to this related question
I have 3 nested divs: outer, inner and item.
<div class="outer">
<div class="inner"><div class="item"></div></div>
</div>
Given the following basic CSS:
.outer{
width:50%;
height:100px;
border: 1px solid red;
position:relative;
overflow-x:hidden;
box-sizing:border-box;
}
.inner{
border:1px solid blue;
height:100%;
position: absolute;
box-sizing: border-box;
line-height:98px;
}
.item{
width:100px;
height:94px;
background-color:yellow;
display: inline-block;
border:1px solid green;
box-sizing:border-box;
vertical-align:middle;
}
The challenge is to center the 'item' div vertically with equal (or no) gaps above/below, and no vertical scrollbars appearing.
Update:
As pointed out below, I should add that multiple items of different heights must be centered. The best answer so far is to add a negative margin to each item, resulting in the following: http://codepen.io/anon/pen/dYWEYZ
However, this smells bad (to me) as it requires an offset that depends on 3 other properties.