Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:39:19+00:00 2026-06-14T19:39:19+00:00

I’m creating an e-commerce site and I’m having trouble vertically centering all my thumbnails.

  • 0

I’m creating an e-commerce site and I’m having trouble vertically centering all my thumbnails. The problem is all my images are different sizes and getting each one to vertical align across all browsers is turning out to be a pain. I’ve looked into the different CSS options, display-table, line-height, and others. They worked in modern browsers, but not well in IE (of course). My thought is the large big time sites are resizing the image (which I can do with no problem) and then overlaying the image on top of a background the exact size they need. Does anyone know if this is how it’s done? IF so can you direct me to some documentation of how to do this in PHP?

Or if someone thinks I can do this without all the extra work of overlaying images please let me know. In-case you want to see what I’m working with here ya go:

HTML

<a href="#">
    <div id="product">
        <div id="product-image">
            <img src="" border="0" />
        </div>
        <div id="product-name"></div>
        <div id="product-price"></div>
    </div>
</a>

OPTION 1 : JQUERY (this seemed to be my best hope, but couldn’t get it to work right)

var h = $('#product-image').height();
$.map($('#product-image img'), function(e)
{
    var top =( h- $(e).height())/2;
    $(e).css("margin-top",top);
});

OPTION 2 : CSS

#product
{
    float:left;
    margin:5px;
    width:200px;
    height:200px;
    border:1px solid #999;
}
#product-image
{
    margin:2px auto;
    width:194px;
    height:145px;
    text-align:center;
}
#product-image img
{
    max-height: 100%;
    max-width: 100%;
    vertical-align:middle;
}

EDIT

I found the working code, thanks Explosion Pills. For anyone trying to get this work I would suggest using this jQuery method and Fiddle link http://jsfiddle.net/9VfUS/1/:

WORKING JQUERY

var h = $('div#product-image').height();
$('div#product-image img').each(function ()
{
    var top = (h - $(this).height()) / 2;
    $(this).css("margin-top",top);
});​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:39:21+00:00Added an answer on June 14, 2026 at 7:39 pm

    If you can use JavaScript, I would do it that way as it’s surefire to get things to work the way you want. You are using .map for the wrong purpose. You want .each:

    $('#product-image img').each(function () {
       var top = (h - $(this).height()) / 2;
       $(this).css("margin-top",top);
    });
    

    I assume that h was already calculated correctly as the tallest image or the height of the container or what have you. If it’s not, then you have to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've tracked down a weird MySQL problem to the two different ways I was
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.