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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:36:04+00:00 2026-06-06T02:36:04+00:00

How do I fit an image in div? Image size can be max then

  • 0

How do I fit an image in div? Image size can be max then div or min then div.

html code

<div class="main">
  <img scr="image.jpg">
</div>

CSS code

.main{
  height:200px;
  width:200px;
}

img{
  // answer code
}

How do I set image css with following:

  1. image height 100 and width 100
  2. image height 300 and width 300
  • 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-06T02:36:07+00:00Added an answer on June 6, 2026 at 2:36 am

    You can use:

    img { max-width: 100%; height: auto; } // This would help you to automatically fit the image.
    

    The above css code would help you for the images whose size is larger than the div. But won’t fit for images which are smaller than the div. A bit of jQuery would be needed to achive your goal, please find it below:

    $(document).ready(function(){
        imageWidth = $('.main img').width();
        parentWidth = $('.main').width();
        if (imageWidth > parentWidth) {
            $('.main img').css('width', '100%');
        }
    });
    

    What happens is when the image is smaller than the div it resizes itself and fits to the div as per your requirement.

    Hence place the css as well as the script to work for both the conditions.

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

Sidebar

Related Questions

How can I resize the image to fit in the size of the div
I have a div, and I want to make a whole background image fit
http://disney.pageonewebsolutions.com/ This website background image perfectly fit to his div. I was wondering if
I'm using background-size: 100%; To fit my background image (in the body-tag) to the
<div id=div1> <img id=img1 src=1.jpg /> <img src=2.jpg /> <img src=3.jpg /> <div style=float:none;clear:both;></div>
I have an image for a background for a div that doesn't exactly fit.
first off here's my current code. <div id=background> <img src=src/1080pTux.png height=100%> </div> #background{ position:fixed;
I have below structure <div class=mybox> <div id=imageslide> <a href=><img src=url /></a> </div> </div>
I need to fit an image inside a 300x300 div without stretching the image.
My goal is totally fit image in toolStripButton and toolStripDropDownButton. If a image in

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.