简体   繁体   English

删除IE9创造的神秘空间<img>

[英]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 我正在尝试学习如何制作跨浏览器页面并停留在处理IE9上:它在<img>附近创建了一些空间,请参见示例

截图

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. 更新:哇,好像我已经知道发生了什么:IE9使图像的高度适合容器的高度,但是以某种方式使实际宽度等于图像的原始宽度。 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 新问题:如何强制IE9使img适合容器并保持宽高比且无魔法

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. 解决此问题,因为在这种情况下将100%视为自动。 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. IE认为从那里开始也具有该宽度,并且由于容器在宽度方向而不是长度方向调整了大小,因此显示了“填充”。

Inherit, on the other hand, resizes the image to fit the container, maintaining the aspect ratio the original image had. 另一方面,继承会调整图像的大小以适合容器,同时保持原始图像的纵横比。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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