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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:44:45+00:00 2026-05-23T01:44:45+00:00

I want to center an image of unknown width/height on a page, while making

  • 0

I want to center an image of unknown width/height on a page, while making sure that it shrinks if it is bigger than the page (i.e. use max-width/max-height).

I tried using the display:table-cell method, but max-width is ignored in Firefox for all elements within elements declared with display:table-cell. Is there a way to vertically center a variable-height element without using display:table-cell?

I can change the mark up. JavaScript is acceptable, but I cannot use JQuery (or any other JS library).

  • 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-05-23T01:44:46+00:00Added an answer on May 23, 2026 at 1:44 am

    This should prove to work quite well… no JavaScript necessary 🙂

    See the working demo on jsFiddle.

    CSS

    /* Don't Change - Positioning */
    .absoluteCenter {
     margin:auto;
     position:absolute;
     top:0;
     bottom:0;
     left:0;
     right:0;
    }
    
    /* Sizing */
    img.absoluteCenter {
     max-height:100%;
     max-width:100%;
    }
    

    HTML

    <img class="absoluteCenter" src="PATHTOIMAGE">
    

    Note: This class can be used for anything quite easily. If you use this for something other than an image, make sure to add a TAG.absoluteCenter CSS rule with a max-height and max-width of your choosing (where TAG is the HTML tag you’re using [e.g. div.absoluteCenter] and max-width/max-height is less than 100%).

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

Sidebar

Related Questions

I have an image that is 100 X 100, and want to center it
I'm trying to use the line-height, vertical-align method to center an image inside a
I want to center image inside a div. The div has fixed width 300px.
I want to use button that background image is mine and text is on
I have a background image about 100 x 100 that I want to center
I want to center a background image. There is no div used, this is
I have an image and some text. I want to center both of them
I want to have my list (nav) align to the center of an image
I want to insert an Image inside my Polygon , possibly at the center
I have a link that I want to center vertically in the .well class

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.