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 7735955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:37:48+00:00 2026-06-01T07:37:48+00:00

i have problem with image vertical-align in div .img_thumb { float: left; height: 120px;

  • 0

i have problem with image vertical-align in div

.img_thumb {
    float: left;
    height: 120px;
    margin-bottom: 5px;
    margin-left: 9px;
    position: relative;
    width: 147px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 3px;
}

.img_thumb img {
    display: block;
    margin-left: auto;
    margin-right: auto;
    vertical-align: middle;
}

<div class="img_thumb">
    <a class="images_class" href="large.jpg" rel="images"><img src="small.jpg" title="img_title" alt="img_alt" /></a>
</div>

As far as i know i need “display: block;” to position image in center and that works.
Also in tutorials i find many answers but they are not “useful”, because all of my image are NOT at the same height!

  • 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-01T07:37:50+00:00Added an answer on June 1, 2026 at 7:37 am

    If you have a fixed height in your container, you can set line-height to be the same as height, and it will center vertically. Then just add text-align to center horizontally.

    Here’s an example: http://jsfiddle.net/Cthulhu/QHEnL/1/

    EDIT

    Your code should look like this:

    .img_thumb {
        float: left;
        height: 120px;
        margin-bottom: 5px;
        margin-left: 9px;
        position: relative;
        width: 147px;
        background-color: rgba(0, 0, 0, 0.5);
        border-radius: 3px;
        line-height:120px;
        text-align:center;
    }
    
    .img_thumb img {
        vertical-align: middle;
    }
    

    The images will always be centered horizontally and vertically, no matter what their size is. Here’s 2 more examples with images with different dimensions:

    http://jsfiddle.net/Cthulhu/QHEnL/6/

    http://jsfiddle.net/Cthulhu/QHEnL/7/

    UPDATE

    It’s now 2016 (the future!) and looks like a few things are changing (finally!!).

    Back in 2014, Microsoft announced that it will stop supporting IE8 in all versions of Windows and will encourage all users to update to IE11 or Edge. Well, this is supposed to happen next Tuesday (12th January).

    Why does this matter? With the announced death of IE8, we can finally start using CSS3 magic.

    With that being said, here’s an updated way of aligning elements, both horizontally and vertically:

    .container {
        position: relative;
    }
    
    .container .element {
       position: absolute;
       left: 50%;
       top: 50%;
       transform: translate(-50%, -50%);
    }
    

    Using this transform: translate(); method, you don’t even need to have a fixed height in your container, it’s fully dynamic. Your element has fixed height or width? Your container as well? No? It doesn’t matter, it will always be centered because all centering properties are fixed on the child, it’s independent from the parent. Thank you CSS3.

    If you only need to center in one dimension, you can use translateY or translateX. Just try it for a while and you’ll see how it works. Also, try to change the values of the translate, you will find it useful for a bunch of different situations.

    Here, have a new fiddle: https://jsfiddle.net/Cthulhu/1xjbhsr4/

    For more information on transform, here’s a good resource.

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

Sidebar

Related Questions

The problem: I have a set width and height image Lets say height:160px; width:200px;
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
I have problem with dynamically created image (JavaScript). I want to change the innerHTML
I have a problem with loading image with java 2ME. I have a image
I have a problem with an image preview that comes up when you hover
I have a problem when I'm trying to delete an image file. I always
I have a problem... In my view i have Image.If i click on image
I have a strange problem where an onclick event on an input image is
I have the following simple button with an image as the template. The problem
Problem Hello all! I have this code which takes my jpg image loops through

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.