Sick of images being to large for the content area?

Have you ever uploaded an image that might have been a tad bigger than the width of your content area? I know I have! So here is a little CSS fix to handle these situations. …

Have you ever uploaded an image that might have been a tad bigger than the width of your content area? I know I have! So here is a little CSS fix to handle these situations.

Resize those large images using CSS

Resize those large images using CSS

.post img {
	max-width: 600px;
	height: auto;
	}

That’s it, really simple huh. Just make sure that you change the .post to the correct body class(which starts with a “.“) or body ID(which starts with a “#“).

Would you like a quick explanation?
The CSS is just telling any image inside the class of .post to not be more than 600px wide. By the way make sure you change it to fit the dimension of your content width. And the height attribute is set to auto to automatically change the height to match the new width. 🙂

7 Comments

  1. Trecar.it

    March 27, 2009

    Simple but very useful css trick, thank you 🙂

  2. cardiogirl

    March 28, 2009

    Hi there, found you through a re-tweet from Lyndi. I love this fix but I am very code-illiterate. Also, attempting to learn XHTML instead of HTML. Where would this go, in the Stylesheet.php or would it go in the post where the image is

    It seems like it would go in the style sheet as an overall rule, right?

    • Austin

      March 28, 2009

      I probably should have written that. Any way, this CSS should go into either an external stylesheet (like, style.css) or in the page head in between

      <style type="text/css">
      .post img {
      	max-width: 600px;
      	height: auto;
      	}
      </style>
  3. cardiogirl

    March 28, 2009

    Oops. I did paste my code from an image in one of my posts and it did not show on my previous comment.

    cardiogirl´s last blog post..The book of questions, Volume 35

  4. Beavisthecat

    September 8, 2009

    I was searching the internet trying to find an easy way to do this. In the past I was loading and reloading my images to make them fit properly. I have bookmarked your site and will check it out more in the future.
    .-= Beavisthecat´s last blog ..Happy Labor Day! =-.