Jump to content

Vertically Align an image


ryanh_106

Recommended Posts

Hi,

 

I want to display 3 random images on my homepage, each time it loads. They are all no more than 200px high or wide (depending on their orientation), but apart from that I cant be sure how high they are.

 

I have a container div which is 230x230 and has a background image of like a raised platform onto which I want the image to be placed. I can then center the image horizontally using text-align but i need some ideas on centering vertically. I know its never easy, but im hoping someone has a cheeky workaround i can use.

 

HTML:

 

<div class="sample">
  <a href="search.php?indexfind=22" title="Click to view property information">
    <img src="includes/image_processor.php?select=22" alt="EXAMPLE PROPERTY" title="Click to view" />
  </a>
</div>

 

CSS:

 

.sample { width:230px; height:230px; display:block; float:left; background-image:url('../../images/box.jpg'); background-position:center center; background-repeat:no-repeat; text-align:center; }
.sample img { margin-top:15px; }

 

Thanks

 

Ryan

Link to comment
https://forums.phpfreaks.com/topic/36582-vertically-align-an-image/
Share on other sites

Hi Andy,

 

Didnt actually use that method in the end (as the images are generated on the fly) but wouldnt have thought of doing it like that without you mentioning it so thanks a lot.

 

Ended up using javascript after the image had been placed to get its height property then change the style to nudge it down the required amount

 

Thanks again

 

Ryan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.