Vertically centering div items inside another div
Just set the container to display:table
and then the inner items to display:table-cell
. Set a height
on the container, and then set vertical-align:middle
on the inner items. This has broad compatibility back as far as the days of IE9.
Just note that the vertical alignment will depend on the height of the parent container.
.cn
{
display:table;
height:80px;
background-color:#555;
}
.inner
{
display:table-cell;
vertical-align:middle;
color:#FFF;
padding-left:10px;
padding-right:10px;
}