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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:17:44+00:00 2026-06-11T22:17:44+00:00

I want to wrap an image into an HTML div and since I want

  • 0

I want to wrap an image into an HTML div and since I want this to be fully scalable with the size of the window, I want to set the width of the div in percentage as follows:

HTML

<div id="wrapper">
    <img src="http://openclipart.org/people/netalloy/rally-car.svg" />
</div>

CSS

#wrapper {
    position: absolute;
    width: 50%;
}

#wrapper img {
    width: 100%;
}

The image should determine the height of its container. This is because the image width is set to 100% and the image height is calculated accordingly, maintaining the correct aspect ratio.

The result is visible on JSFiddle.

My questions are:

  1. Why do all modern browsers render the wrapper div 5px taller than the inner image?
  2. How can I get rid of this 5px gap, while still setting all the sizes in percentage and without using JavaScript?

Surprisingly, this happens in

  • Chrome (21.0.1180.89)
  • Firefox (15.0.1) and
  • IE8

while IE7 renders it correctly, matching the height of the div with the height of the image.

  • 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-11T22:17:46+00:00Added an answer on June 11, 2026 at 10:17 pm

    OK, fiddling about, I found a good possible solution:

    #wrapper img {
        display: block;
        width: 100%;
        border: 1px dashed red;
    }
    

    Changing from the default inline display to a block display eliminates the line-height problem straight away.

    This approach is also semantically correct because in this case what we really want is a single image wrapped in a div without any other elements in it, so the concept of line-height needs to be completely wiped off by displaying the image as a block.

    It works on all major browsers: Demo

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

Sidebar

Related Questions

i am generating html control dynamically and now i want to wrap the html
I want to display some div's in a wrap. The div have same class
Currently I have this JQuery script var img = $(this); img.wrap('<div class=photo></div>'); img.parent().append(<p> +
I want to wrap the text like you wrap text around an image but
Before I explain... This is the HTML part: <div class=HeadingTabs> <ul> <li><a href=http://google.com class=TabLink>Google</a></li>
I want to load different content into a div based on a drop-down selection.
I have a numpy array and want to convert it into an ITK image
I want to wrap around a list/vector in C++ like in Python. Basically I
I want to wrap some queries in a SharedDbConnectionScope and execute them under a
in a project we want to wrap the Boost Asio socket in a way,

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.