CSS: Resizing Large Images to Fit in Containers (also work in MSIE!)

March 28, 2005 by  
Filed under CSS, Scripts and Coding

In my post about CSS: Resizing Large Images to Fit in Containers, I hadn’t noticed that the CSS2 code, “max-width” didn’t work in MS Internet Explorer. So I looked around and found this nice piece of code from Ozone Asylum Forums (based on this article).

So to make an image resize in MSIE, use this CSS Code.

<html>
<head>

<style type=”text/css”>

.resizeImage {

/* for Firefox, Opera and others: */

max-width: 250px;

}

</style>

<!–[if gte IE 5]>

<style type=”text/css”>

.resizeImage {

/* For Internet Explorer: */

width: expression(Math.min(parseInt(this.offsetWidth), 250 ) + “px”);

}

</style>
<![endif]–>
</head>

<body>

<img src=”myimage.jpg” class=”resizeImage” alt=”my image” />
</body>
</html>

So that’s how you get the ‘max-width’ CSS property to work in Internet Explorer? …You don’t. ;) Just use width and the Javascript trick! Thank you for pointing this out to me how max-width didn’t work in MSIE, John Adams.

Resources: Ozone Asylum Forums, svendtofte.com.

Related Products:

How to Diagnose and Fix Everything ElectronicHow to Diagnose and Fix Everything Electronic

 Master the Art of Electronics Repair In this hands-on guide, a lifelong electronics repair guru shares his tested techniques and invaluable insig... Read More >

HDMI Cable 2M (6 Feet)HDMI Cable 2M (6 Feet)Perfect for connecting your HDTV, DVD/Blu-Ray players, gaming systems, and other home theater/entertainment components.These HDMI cables are ATC (Authorized Testing Center) certified, meaning you can count on them to pass a high-definition signal up to 1080p.
Kindle Fire, Full Color 7" Multi-touch Display, Wi-FiKindle Fire, Full Color 7" Multi-touch Display, Wi-FiMovies, apps, games, music, reading and more, plus Amazon's revolutionary cloud-accelerated web browser - 18 million movies, TV shows, songs, magazine... Read More >
Related Posts Plugin for WordPress, Blogger...

Popularity: 13% [?]

  • http://danwu.net/blog Daniel

    Hi,

    I found your blog when I was searching for a solution to the max-width issue in wordpress. I’m a newbie at this whole css thing :-P I have a few questions.

    1. Do I append this code to the style.css file? Anywhere in the file?

    2. Do I need to include the “p img { max-width: 100%; }” as well as the code you mentioned above, or does the above trick work take care of the resizing in firefox as well?

    3. Is this code application to other themes as well, or just the MX4 theme?

    4. what’s the myimage.jpg reference?

    Thanks!

  • http://danwu.net/blog Daniel

    Hi,

    I found your blog when I was searching for a solution to the max-width issue in wordpress. I’m a newbie at this whole css thing :-P I have a few questions.

    1. Do I append this code to the style.css file? Anywhere in the file?

    2. Do I need to include the “p img { max-width: 100%; }” as well as the code you mentioned above, or does the above trick work take care of the resizing in firefox as well?

    3. Is this code application to other themes as well, or just the MX4 theme?

    4. what’s the myimage.jpg reference?

    Thanks!

  • http://daynah.net daynah

    1. You can put half of it your style.css file, except it’s probably easier to put it in the header of each theme since it needs the “if this is MSIE” code. Put it anywhere between the <head> tags.

    2. If you are using it for wordpress themes, instead of using “.resizeImage” use, “p img” instead.

    3. You can use it in any theme.

    4. myimage.jpg is the image you post in your post.

    I hope that helps. You might want to read up on more CSS articles before attempting to edit your files though. This is a good place to start: http://www.w3schools.com/css/default.asp

  • http://daynah.net daynah

    1. You can put half of it your style.css file, except it’s probably easier to put it in the header of each theme since it needs the “if this is MSIE” code. Put it anywhere between the <head> tags.

    2. If you are using it for wordpress themes, instead of using “.resizeImage” use, “p img” instead.

    3. You can use it in any theme.

    4. myimage.jpg is the image you post in your post.

    I hope that helps. You might want to read up on more CSS articles before attempting to edit your files though. This is a good place to start: http://www.w3schools.com/css/default.asp

Stop SOPA!

SOPA breaks our internet freedom!
Any site can be shut down whether or not we've done anything wrong.

Stop SOPA!