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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:41:45+00:00 2026-06-14T03:41:45+00:00

My question is simple. Let’s say I have two rectangular images. The first is

  • 0

My question is simple. Let’s say I have two rectangular images. The first is 200px wide and 100px tall, and the second is 100px wide and 200px tall.

I want to display the images with a constant width/height, e.g. 150px by 150px without stretching the images to fit:

enter image description here

I don’t mind having whitespace/padding around the images. The problem is that the images could be of any width and height, and I want to limit them to a square box without stretching them.

The following CSS stretches the images to fit to 150px by 150px:

img {
    width: 150px;
    height: 150px;
}

The most preferable solution is CSS, even if I need a little more markup. JS/jQuery is okay as well though.

  • 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-14T03:41:46+00:00Added an answer on June 14, 2026 at 3:41 am

    What about:

    img {
        max-height:150px;
        max-width:150px
    }
    

    To achieve your 2nd question on making smaller images bigger, you can do with jQuery. CSS could work if you knew the photo orientation before hand and applied a different css class to those images… But this will work and then you don’t need the CSS max-width stuff any more.

    <div class="container"><img src="images/DSC_0470.JPG" alt="Rad Image" /></div>
    
    <script>
        $(document).ready(
            function () {
                $('.container img').each(
                function () {
                    var theWidth = $(this).width();
                    var theHeight = $(this).height();
                    if (theWidth < theHeight) {
                        $(this).height(150);
                    }
                    else {
                        $(this).width(150);
                    }
    
                });
            });</script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is one very simple question(or at least at first sight).Let's say we have
I have a simple question. Let's say I have a .Net solution, with different
I believe my question this time is simple. Let say I have a webpage,
I have a simple question. Let's say I have a drawable image. If I
I have a simple question about filtering attributes in WEKA. Let's say I have
i have simple question, let's say i have input like this: <input name=somename type=checkbox
Simple question. Let's put on our engineer/project manager hat for a second: You have
Simple question : I have a service class (let's say helpersService ) and a
The question is simple. Let's say I have a model. I need default data
I have a little simple question. Let's say I have a data object with

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.