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

  • Home
  • SEARCH
  • 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 8175837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:55:11+00:00 2026-06-06T22:55:11+00:00

I have an image inside a div like this <div><img /><div> The image is

  • 0

I have an image inside a div like this

<div><img /><div>

The image is dynamic of no fixed size. The div is of size 200px by 200px. The image size is not known beforehand. If the size of the image is greater than 190px by 190px, set it to 190px by 190px (that is, max-width:190px, max-height:190px). How can I center the image with these needs satisfied? I need a solution working in Internet Explorer 7 too.

The solution here and here can not be applied to my problem because

  1. It is not certain that the image would be less than 200 pixels.

  2. I want horizontal alignment too.

  3. No Internet Explorer 7 support.

(Some questions have been asked on Stack Overflow regarding the same, but my scenario is different, so they are not applicable for this particular problem.)

  • 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-06T22:55:12+00:00Added an answer on June 6, 2026 at 10:55 pm

    The solution is to change the div into a table. Normally, you shouldn’t use tables for positioning, but when it comes to older non-standards-compliant browsers, sometimes that’s the only choice. Demonstration here. For the record, this works on Internet Explorer 6, as well.

    Code:

    CSS

    #theDiv
    {
        width: 200px;
        height: 200px;
        text-align: center;
        vertical-align: middle;
    }
    #theImg
    {
        max-width: 190px;
        max-height: 190px;
    }​
    

    ​HTML

    <table id="theDiv" style="border: solid 1px #000">
        <tr>
            <td>
        <img id="theImg" src="http://cdn1.sbnation.com/community_logos/9156/gangreen-small.jpg" />
            </td>
        </tr>
    </table>
    

    Here’s an update that uses CSS instead of changing the markup to an actual table:

    #theDiv
    {
        display: table;
        width: 200px;
        height: 200px;
        text-align: center;
        vertical-align: middle;
    }
    #theImg
    {
        max-width: 190px;
        max-height: 190px;
    }
    
    .tr {
      display: table-row;
    }
    .td { 
      display: table-cell;
      vertical-align: middle;
    }
    
    <div id="theDiv" style="border: solid 1px #000">
        <div class="tr">
            <div class="td">
        <img id="theImg" src="http://lorempixel.com/100/100/" />
            </div>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div contain the image inside it like this : <div class=gallery
I have an image inside a div, like so: <div><img src= class=draggable></div> It's a
I have this div and inside the div is an image, and what I
I have multiple containers like this <div class=container> <span> <!-- Inside the span is
i have simple html that looks like this : <div class=img> <a target=_blank href=kl_big.htm
I have a very simple div with an image inside: <div class=stack4> <img src=images/002m.jpg
I have an image inside a div.. the div has a background picture..and I
I have a thumbnail image inside a div. I use another image as the
I have an image and a hyperlink inside a div, but for some reason,
I have a div and an image inside it as a background: <div id=background>

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.