3

we have CSS:

#left,#right{width:450px;height:450px;}
#left{position:absolute;left:20px;top:30px;}
#right{position:absolute;left:420px;top:30px;float:center;}

#left img, #right img{float:center; vertical-align:middle;cursor:pointer}

Image is horizotal centered, but gets top aligned (i want middle)

html looks like

<div id="media">
    <div id="left"><img/></div> <div id="right"><img/></div>
</div>

Any idea what i'm doing wrong?

By the way, all this problem it's because i'm displaying images with different resolutions :S

EDIT

This didn't help... :(

#left,#right{width:450px;line-height:450px;}
#left{position:absolute;left:20px;top:30px;}

#right{position:absolute;left:420px;top:30px;float:center;}
#left img,#right img{cursor:pointer;}
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

3 Answers3

4

you can vertical align an image in a div that has no text in it by setting line-height on the on the div. example:

<div style="height: 100px; line-height: 100px;">
    <img src="http://nelson-haha.com" height="50" style="vertical-align: middle;"/>
</div>
pmko
  • 5,071
  • 3
  • 23
  • 25
3

You'll first off need to have some height declared on #left or #right to get it to align vertically. (As it is, it has no more known space to align vertically in than the space it's taking up--so it will always appear top-aligned.)

Secondly, make sure you understand vertical-align correctly. Here's a good resource: http://phrogz.net/css/vertical-align/index.html In short, vertical-align is probably not the best solution.

0

vertical-align on an image is how the text aligns to the image, the way the text wraps around the image. Not the way the image is displayed in the div.

Please see this on StackOverFlow

Community
  • 1
  • 1
SQLMason
  • 3,275
  • 1
  • 30
  • 40
  • i see, but my problem is that i'm playing with horzontal and vertical images.... that post only seems to help if you know dimensions already, but thanks! – Toni Michel Caubet Apr 01 '11 at 17:30