If you do not need support for Internet Explorer 8 or the project is more flexible, you can also use the following code:
.vertical-align {
position: relative;
top: 50%;
transform: translateY(-50%); /* Adicionar os prefixos dos navegadores */
}
Source - link
It's also worth remembering that using display:table
does not work with float
.
Another solution, for those who need support under Internet Explorer 8:
.vertical-align {
display: block;
}
.vertical-align > div {
display: block;
position: relative;
margin-top: inherit;
clear: ~'expression(style.marginTop = "" + (offsetHeight < parentNode.offsetHeight ? parseInt((parentNode.offsetHeight - offsetHeight) / 2) + "px" : "0"), style.clear = "none", 0)';
}
Another solution if Internet Explorer 6 support is required:
.vertical-align {
position: relative;
}
.vertical-align > div {
position: absolute;
top: 50%;
}
.vertical-align > div > div {
position: relative;
top: -50%;
}
Source - link