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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:56:17+00:00 2026-06-10T02:56:17+00:00

Possible Duplicate: vertical alignment of image inside a div OK, this what I’m trying

  • 0

Possible Duplicate:
vertical alignment of image inside a div

OK, this what I’m trying to do :

  • I’m having an empty div (a box), with almost no height.
  • I’m making an AJAX request to load some content into it.
  • Before loading the content, I want to display in a typical “ajax loading” rotating gif.

I’ve managed to :

  • Center the img horizontally (by putting it inside another div with text-align:center;)

What is left :

  • Be able to give some height to that empty div. (easy)
  • Vertically align the image, so that it appears on the very center of the box. (I’ve got absolutely no idea how to do this. I’m currently setting an upper margin, which works for one particular box, but which wouldn’t work if the box already has some different height…)

How would you go about it?? (Any possible idea is acceptable. CSS/Javascript whatever…)

  • 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-10T02:56:18+00:00Added an answer on June 10, 2026 at 2:56 am

    http://jsfiddle.net/teresko/5mG2y/

    The basic idea is the use display: table-cell; and then vertical-align: middle;

    the HTML

    <div class="container">
        <div class="holder">
            <img class="stuff" src="path/to/image.png">
        </div>                
    </div>
    

    the CSS:

    .container{ 
        /* the container in which image is placed */
        height:         300px;
        margin:         0 auto;
        width:          200px;
    }
    
    .holder{
        display:        table-cell;
        width:          100%;
        vertical-align: middle;
        height:         inherit;
    }
    
    .stuff{
        display:        block;
    }
    

    This way the placement of image will not depend on dimensions of container. It also can be adjusted to be in horizontal center too. All you have to do is to add .stuff{ margin: 0 auto;}.

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

Sidebar

Related Questions

Possible Duplicate: css vertical centering I'm trying to get text centered in a vertical
Possible Duplicate: How to set android show vertical orientation? I'm trying to disable auto
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: How do I center text horizontally and vertical in a TextView in
Possible Duplicate: Disable browsers vertical and horizontal scrollbars Can I disable vertical scroll bar
Possible Duplicate: embedding background image data into css as base64, good or bad practice
Possible Duplicate: to fit iframe to its content height As is described in the
Possible Duplicate: how to make surfaceview transparent I am trying to make a custom
Possible Duplicate: setOnClickListener not working and throwing error I am trying to develop a

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.