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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:03:52+00:00 2026-05-27T05:03:52+00:00

html: <div id=thumbnail> <img src=xxx> </div> css: div.thumbnail { border: 2px solid #ccc; width:

  • 0

html:

<div id="thumbnail">
  <img src="xxx">
</div>

css:

div.thumbnail
{
border: 2px solid #ccc;
width: 50px;
height: 50px;
overflow: hidden;
}

Say the image size is greater than 50×50, is there any way that I can proportionally scale down the image so that the shorter of its width and height would become 50px? Note that the image can be in either portrait or landscape.

  • 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-27T05:03:52+00:00Added an answer on May 27, 2026 at 5:03 am

    First load up the image in javascript to get its real dimensions.

    var img = new Image('image.jpg');
    var width = img.width;
    var height = img.height;
    

    Then determine which one has the larger height, and adjust them accordingly using the ratios.

    if (width <= height) {
        var ratio = width/height;
        var newWidth = 50;
        var newHeight = 50 * ratio;
    } else {
        var ratio = height/width;
        var newWidth = 50 * ratio;
        var newHeight = 50;
    }
    

    Then insert the image into the DOM using jQuery.

    $('#imageContainer').append('<img src="' + img.src + '" style="width:' + newWidth + 'px; height:' + newHeight + 'px;" />');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HTML: <div> <img src=some/path/ class=thumbnail /> <input type=file class=image_upload /> </div> CSS: div {
I have this HTML with a table: <div class=currentDesignDiv style=margin-bottom:5px;> <div> <img alt=Thumbnail src=http://www.propertyware.com/templates/
I just saw this code in an answer: HTML <div class=thumbnail> <img src=http://placehold.it/50x50> <img
Day 2 The html... <div id=galleria> <div class=images><a href=../Bens_Internet_Erik/bens_img/image_impfstoffbehaelter.jpg><img src=../Bens_Internet_Erik/bens_img/thumbnail_impfstoffbehaelter.jpg ></a></div> <div class=images><a href=../Bens_Internet_Erik/bens_img/image_abfuellnadel.jpg><img
I have this divs in my html <img src=images/cocina1.jpg name = main_img alt=alternate_text height=250
$(this).parent().parent() .children(this.attr(tagName).toLowerCase()) .css(background-color, yellow); xpath: /html/body/div/table/tr/td/b/a $(this).tagName is Anchor <a> the problem with this
I am trying to generate an html div in asp.net. Since a div is
What is the best way to set the transparency of a HTML DIV element
how can i convert xpath like /html/body/div[3]/ul/li[1]/a[5] html > body > div[3] > ul
Given: Url - http://www.contoso.com/search.php?q= {param} returns: -html- --body- {...} ---div id='foo'- ----div id='page1'/- ----div

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.