Vertical Align Block Elements

A tale of browser incompatibilities

Method 1 - Multiple lines of content (with fixed height)

The way to accomplish vertical centering is as follows:

  1. Specify the parent container as position:relative or position:absolute.
  2. Specify a fixed height on the child container.
  3. Set position:absolute and top:50% on the child container to move the top down to the middle of the parent.
  4. Set margin-top:-yy where yy is half the height of the child container to offset the item up.

Method 2 - Single lines of content

To use this method do the following:

  1. Set the line-height of the parent element to the fixed height you want.

CSS

Ads