Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

How To Vertically Align Content

My Simple Method

9:29 pm on Sep 1, 2008 (gmt 0)

5+ Year Member

I've found that vertical-alignment is a popular topic in this forum (and probably other web design forums as well). As such I wanted to post my simple solution for myself and others to reference.

Before I provide the code, here is the explanation: Many of us have tried to use vertical-align on divs, with no success. The reason being that vertical-align aligns content according to line-height... OR image height! By using a 100% height image - you can vertically align inline content (NOT BLOCK CONTENT!).

But you don't always want to put an image in wherever you want to vertically align content. Fortunately, you can set the images visibility to hidden and it will still work!

Here is the CSS:

vertical-align:middle; /*or other accepted alignment*/

Remember this must be applied to images only! For example:

<div id="content">
<img class="valigner"> <!-- You don't need to specify src -->

Tell me what you think!