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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:16:25+00:00 2026-06-11T07:16:25+00:00

I am wondering if it is possible to keep an img inside a div

  • 0

I am wondering if it is possible to keep an img inside a div always centered regardless of the browser size? By being centered I mean that the left/right sides of the image gets cropped to ensure the image stays centered without modifying the height. Also, is it possible to prevent the horizontal scroll bar from appearing when the browser width is less then the image width?

I’m sure this is really easy to do if my image is located in a background-url tag in CSS, but because this image is being housed inside the SlidesJS carousel the image has to be from an img tag.

At the moment, I have used margin:0 auto; to keep the image centered as long as the browser width is larger then the image. Once the browser width shrinks, the image does not resize with the shrinking browser size. I also have yet to figure out how to remove the horizontal scroll bar when the browser width is too small.

This is what I’m trying to achieve: https://i.stack.imgur.com/amw3O.jpg

This is an example of what the page layout is suppose to look like: https://i.stack.imgur.com/8J8O7.jpg

Example of my code: http://jsfiddle.net/9tRZG/

HTML:

<div id="wrapper">
    <div id="slides">
        <div class="slides_container">
            <div class="slide"> <!-- Carousel slide #1 -->
                <img src="http://www.placehold.it/200x50/">
            </div>
            <div class="slide"> <!-- Carousel slide #1 -->
                <img src="http://www.placehold.it/200x50/">
            </div>
            <div class="slide"> <!-- Carousel slide #1 -->
                <img src="http://www.placehold.it/200x50/">
            </div>
        </div>
    </div>
</div>​

CSS:

#wrapper {
    width: 200px;
    margin: 0 auto;
}​
  • 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-11T07:16:26+00:00Added an answer on June 11, 2026 at 7:16 am

    Try this: http://jsfiddle.net/9tRZG/1/

    #wrapper {
        max-width: 200px; /* max-width doesn't behave correctly in legacy IE */
        margin: 0 auto;
    }
    #wrapper img{
        width:100%;       /* the image will now scale down as its parent gets smaller */
    }
    ​
    

    To have the edges cropped, you can do this: http://jsfiddle.net/9tRZG/2/

    #wrapper {
        max-width: 600px; /* so this will scale down when the screen resizes */
        margin: 0 auto;
        overflow:hidden;  /* so that the children are cropped */
        border:solid 1px #000; /* you can remove this, I'm only using it to demonstrate the bounding box */
    }
    
    #wrapper .slides_container{
        width:600px;            /* static width here */
        position:relative;      /* so we can position it relative to its parent */
        left:50%;               /* centering the box */
        margin-left:-300px;     /* centering the box */
    }
    #wrapper img{
        display:block;          /* this allows us to use the centering margin trick */
        margin: 2px auto;       /* the top/bottom margin isn't necessary here, but the left/right is */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering ( if possible ) if there was a program/tool/utility that when
Just wondering is it possible to build CLI app that can be run from
I was wondering - is it possible to change files that are stored on
Is it possible to change the div's font-size depending on how many characters are
Possible Duplicate: What does the >?= operator mean? I was wondering what is the
I was wondering if it is possible to keep some data even after refreshing
I'm wondering if it is possible to keep an HTML page in view, or
This may be impossible, but I was wondering if it was possible to keep
i'm wondering if it's possible to build a facebook app that runs as a
I'm writing a navigation and im just wondering if its possible to keep the

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.