Welcome to WebmasterWorld Guest from 54.162.226.212

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:


.valigner
{
height:100%;
vertical-align:middle; /*or other accepted alignment*/
visibility:hidden;
width:0px;
}

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

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

Tell me what you think!

Ryan

 

Featured Threads

Hot Threads This Week

Hot Threads This Month