简体   繁体   English

使用最大宽度时,图像无法在IE8中居中吗?

[英]Image not centering in IE8 when using max-width?

I have a table that contains an image, but for some reason I cannot get certain images to center correctly. 我有一个包含图像的表,但是由于某种原因,我无法使某些图像正确居中。 When I apply max-width:170px the image resizes correctly, but it does not center. 当我应用max-width:170px ,图像会正确调整大小,但不会居中。 In every other browser (even IE7) everything looks good, but IE8 chokes. 在所有其他浏览器(甚至是IE7)中,一切看起来都不错,但IE8却令人窒息。 Here is the FIDDLE http://jsfiddle.net/5VT7e/ . 这是FIDDLE http://jsfiddle.net/5VT7e/

Note: I created the fiddle in Chrome, but went to view it in IE8 and I guess JSFIDDLE doesn't work in IE8. 注意:我在Chrome中创建了小提琴,但是在IE8中查看了它,我想JSFIDDLE在IE8中不起作用。 None-the-less you can view all the code ;) 不过,您可以查看所有代码;)

Here's a screen shot of the problem: 这是问题的屏幕截图:

Problem: 问题: 在此处输入图片说明

Desired: 期望的: 在此处输入图片说明

  • First image looks okay 第一张图片看起来还不错
  • Second image is shifted to the right 第二张图像向右移动
  • Third image looks okay 第三张图片看起来还可以
  • Fourth image is shifted to the right 第四张图像向右移动
  • Fifth image is shifted to the right 第五张图像向右移动

Pretty much any image that max-width:170px effects is shifted to the right. max-width:170px效果的几乎所有图像都向右移动。

Thanks for having a look. 感谢您的浏览。

This answer provides two possible solutions: 该答案提供了两种可能的解决方案:

  1. Set width: auto on your images 设置width: auto显示图像
  2. Provide a width on the direct parent element of the images. 在图像的直接父元素上提供宽度。

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

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