Search code examples
cssimageinternet-exploreralignment

CSS: Aligning Images in IE vs. Firefox or Chrome - Image size all screwed up


Kind of a frustrating question for me.

Here's the link. Try it in IE, Chrome and Firefox. The latter two are fine and the image is aligned to the right and appears as 375x500. But in IE, the image aligns to the right, but appears as 15x500.

http://www.themoneygoround.com/2011/04/intc-intel-shows-up-strong-afterhours.html

When I look at the View Source in IE, the image width and height should be 375x500, but that's not what displays. The image is aligned to the right as expected, but shrunk to 15x500. Thanks for any thoughts...

Here is the CSS

p img {
    padding: 0;
    max-width: 100%;
    }

img.centered {
    display: block;
    margin-left: auto;
    margin-right: auto;
    }

img.alignright {
    padding: 4px;
    margin: 0 0 2px 7px;
    display: inline;
    }

img.alignleft {
    padding: 4px;
    margin: 0 7px 2px 0;
    display: inline;
    }

.alignright {
    float: right;
    }

.alignleft {
    float: left;
    }
/* End Images */

Solution

  • I see the problem as well with IE 8. The trouble is your max-width property for the <img>. IE will not render a max-width correctly with the XHTML doctype (which you appear to be using). You can either remove the max-width or use a doctype which will trigger standards mode in IE. I recommend the HTML5 doctype as per this article.