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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:37:27+00:00 2026-05-28T03:37:27+00:00

I want a <img> whose width is 40% of the page, and it gets

  • 0

I want a <img> whose width is 40% of the page, and it gets stretched.

How can I resize it without stretching?

For example, if I have a image whose file originally looks like this:

____8888________
____8888________
____8888________

In my webpage, normally, it should looks like:

____8888________
____8888________
____8888________

As soon as I make the browser a little more narrow, the max-width(let’s say 10 characters in this example) would take effect.
When that happens, I would like it to be:

____8888__
____8888__
____8888__

(just like it’s been cut from the right side. Of course from both sides are better),
Rather than:

__888_____
__888_____
__888_____
  • Any trick (putting it into a <div>‘s background) is okay.
  • Width and height are unknown.
  • Thank you all for your previous answers, but, sorry, I think I haven’t put enough emphasis on “After limiting its width to 40% of the page”, which means before width-limiting it should looks normal.
  • 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-28T03:37:27+00:00Added an answer on May 28, 2026 at 3:37 am

    The trick is to put the image into a containing block element, eg a DIV. Once inside set the width of the image to 100%, this will instruct the browser to fit the image width flush with the left and right edges of the DIV.

    You then control the width of the DIV via CSS, I find keeping the image in a block element makes manipulation much easier when creating fluid layouts.

    Example:

    img.stretchy {
    width: 100%; /*Tells image to fit to width of parent container*/
    }
    .container {
    width: 33%; /*Use this to control width of the parent container, hence the image*/
    }
    <div class="container">
       <img src="https://i.stack.imgur.com/fv6Ib.jpg" alt="Beach Scene" class="stretchy" />
    </div>

    If you wan the image to be clipped/cropped in any way, set it to be larger than it’s parent, and set the parent’s overflow css to hidden.

    Example:

    img.clipped {
        width: 150%; /*Scales image to 150% width of parent container*/
        float: left; /*Floats image to left of container - clipping right hand side*/
        float: right; /*Floats image to right of container - clipping left hand side*/
    }
    .container {
        width: 33%; /*Use this to control width of the parent container, hence the image*/
        overflow: hidden;
    }
    <div class="container">
       <img src="https://i.stack.imgur.com/fv6Ib.jpg" alt="Beach Scene" class="clipped" />
    </div>

    Hope this helps…

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

Sidebar

Related Questions

I have a div whose contain a flash and a image,and I want them
The situation is I have an img and I want a pop-over caption-box whose
I want to save a remote img-file to my server, but I don't know
I want to call a Servlet from img src. I have defined a Servlet
I have a folder named img and i want to use js to look
i have a simple website: fixed width, variable height, centered. I want a background
I want to find an img tag in a string. I wrote for example:
I have a web page whose large parts are constructed on the front-end, in
I have a table, of whose number of columns can change depending on the
How can I extract a value of an <img> tag from a page that's

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.