PDA

View Full Version : Vertically Aligning an Image within a Div



MaggieBroon
June 15th, 2006, 05:33 PM
I am going round the twist trying to figure out something that is probably dead easy!

I am trying to vertically align an image within a div and it doesnt seem to be working.

The page is here (http://freespace.virgin.net/stuart.lawson/johnlaidlaw/new/). Could someone take a look and point me to where I'm going wrong? Its the logo at the top :)

Thanks,
Mags x

Flashback10
June 15th, 2006, 05:51 PM
Try <div valign="middle"></div>

Jeff Wheeler
June 15th, 2006, 06:12 PM
You need something like this:

div {
position: relative;
}

img {
margin-top: -[image height (note the - before this)];
position: absolute;
top: 50%;
}

It utilizes Bowman's Making the Absolute, Relative.

MaggieBroon
June 16th, 2006, 02:45 AM
Thanks for the quick reply guys! I'm really new to css & table-less layouts :puzzled:

Could you explain where I should put that code NoKrev? Is it in the css or in the html?

Cheers! :)

Jeff Wheeler
June 16th, 2006, 12:13 PM
Put that in the css (it's css source), but change the selectors to apply to the div and img you are using.