I'm aware this question was asked over two years ago, but for any recent viewers, here's an alternative solution, which has a few advantages over Marc-François's solution:
div {
height: 50px;
border: 1px solid blue;
line-height: 50px;
}
Here we simply only add a line-height
equal to that of the height of the div. The advantage being you can now change the display property of the div as you see fit, to inline-block
for instance, and it's contents will remain vertically centered. The accepted solution requires you treat the div as a table cell. This should work perfectly, cross-browser.
The only other advantage being it's just one more CSS rule instead of two :)
Cheers!