verticle align image problem

This is a discussion on "verticle align image problem" within the Web Page Design section. This forum, and the thread "verticle align image problem are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 4th, 2007, 18:09
New Member
Join Date: Mar 2007
Location: uk
Age: 99
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
verticle align image problem

Hi guys,

I've got an img inside a div, how can I center it vertically with the div?

This is my code:

Code: Select all
<div style="width:100px; height:200px; line-height:200px; vertical-align:middle">
     <img style="height:135px; vertical-align:middle" src="http://www.whatever.com/1.jpg">
</div>

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 4th, 2007, 18:14
New Member
Join Date: Mar 2007
Location: uk
Age: 99
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: verticle align image problem

nevermind!

solution found lol:

Code: Select all
<div style="height:200px; line-height:200px;">
       &nbsp;<img style="height:135px; vertical-align:middle" src="http://www.whatever.com/1.jpg">
</div>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 4th, 2007, 18:22
New Member
Join Date: Jul 2007
Location: Kent, UK
Age: 25
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: verticle align image problem

Probably the simplest method if you know the height of the image, as you do in your example. Things get more complicated if the height of the content is variable.

top: 50% moves the image down to the half way point, then the negative top margin (half the value of the image height, drags it up to be centrally aligned.

Code: Select all
<div style="width:100px; height:200px; position: relative;">
     <img style="height:135px; position:absolute; top:50%; margin: -68px 0 0 0;" src="http://www.whatever.com/1.jpg">
</div>
Edit: or that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
verticle align

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
div align problem vobla Web Page Design 10 Apr 8th, 2008 09:52
Verticle Alignment? PicoDeath Web Page Design 1 Jul 27th, 2007 18:21
textformat.align problem janper Flash & Multimedia Forum 1 Apr 13th, 2007 21:57
center align text/background image Lchad Web Page Design 5 Dec 5th, 2006 10:40
Align problem Amphersand Web Page Design 3 Oct 11th, 2006 17:11


All times are GMT. The time now is 14:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42