简体   繁体   中英

Remove mysterious space that IE9 creates around <img>

I'm trying to learn how to make crossbrowser pages and stuck at dealing with IE9: it creates some space near the <img> , see example

截图

Look at the rightmost image, it should appear here. If space doesnt appear, hover the mouse over the image.

Can't imagine what's wrong, this image is only floated to left...

UPDATE: wow, seems like i've found out whats going on: IE9 makes image's height fit the height of container, but somehow make actual width equal to image's original width. But still keeps aspect ratio of image.

New question: how to force IE9 to make img fit into container with keeping aspect ratio and without magic

Changing this:

.header * {
  float: left;
  height: 100%;
}

To this:

.header * {
  float: left;
  height: inherit;
}

Fixes it as 100% is treated as auto in this scenario. Auto in this case is the size of the original image: not the size of the container. From there, IE believes it also has that width, and because the container resizes width-ways and not length-ways, the 'padding' is shown.

Inherit, on the other hand, resizes the image to fit the container, maintaining the aspect ratio the original image had.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM