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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:46:17+00:00 2026-06-04T20:46:17+00:00

I am trying to resize an image with a percentage of itself. For example,

  • 0

I am trying to resize an image with a percentage of itself. For example, I just want to shrink the image by half by resizing it to 50%. But applying width: 50%; will resize the image to be 50% of the container element (the parent element which maybe the <body> for example).

Question is, can I resize the image with a percentage of itself without using JavaScript or server side? (I have no direct information of the image size)

I am pretty sure you cannot do this, but I just want to see whether there are intelligent CSS only solution. Thanks!

  • 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-04T20:46:20+00:00Added an answer on June 4, 2026 at 8:46 pm

    I have 2 methods for you.

    Method 1.

    This method resize image only visual not it actual dimensions in DOM, and visual state after resize centered in middle of original size.

    img {
      transform: scale(0.5);
    }
    <img src="https://via.placeholder.com/300x200" />

    Browser support note: browsers statistics showed inline in css.

    Method 2.

    #wrap {
      overflow: hidden;
      position: relative;
      float: left;
    }
    
    #wrap img.fake {
      float: left;
      visibility: hidden;
      width: auto;
    }
    
    #img_wrap {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
    }
    
    #img_wrap img.normal {
      width: 50%;
    }
    <div id="wrap">
      <img class="fake" src="https://via.placeholder.com/300x200" />
      
      <div id="img_wrap">
        <img class="normal" src="https://via.placeholder.com/300x200/cccccc" />
      </div>
    </div>

    Note: img.normal and img.fake is the same image.
    Browser support note: This method will work in all browsers, because all browsers support css properties used in method.

    The method works in this way:

    1. #wrap and #wrap img.fake have flow
    2. #wrap has overflow: hidden so that its dimensions are identical to inner image (img.fake)
    3. img.fake is the only element inside #wrap without absolute positioning so that it doesn’t break the second step
    4. #img_wrap has absolute positioning inside #wrap and extends in size to the entire element (#wrap)
    5. The result of the fourth step is that #img_wrap has the same dimensions as the image.
    6. By setting width: 50% on img.normal, its size is 50% of #img_wrap, and therefore 50% of the original image size.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to resize an image with the maximum of 1000px width but
I am trying to resize the image using javascript, but I am getting errors
I'm trying to resize an image using stretchableImageWithLeftCapWidth: it works on the simulator, but
Using this code I am trying to resize the selected image and then want
I've been trying to resize an image using php but I'm having issues getting
I'm a php noob and trying to create a image resizing script that will
I'm trying to resize a ccsprite image. My wanted resizing way is to decrease
I'm trying to resize an image at runtime in yii, but does not work.
I am trying to resize an image based off of a max-width/max-height array. Here's
I'm trying to resize an large image, but the out come of the image

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.