+10  A: 

Set your CSS overflow property on the div to one of these:

overflow: auto;    /* Adds scrollbars only when necessary */
overflow: scroll;  /* Adds inactive scrollbars until needed, then activates */
overflow: visible; /* Causes the div to expand to fit the content */
overflow: hidden;  /* Hides any content that overflows */
Joe Philllips
+3  A: 

Generally speaking, with large images you want to thumbnail them and not automatically display them, particularly if they're over a certain size.

Using the height and width CSS attributes (or the height and width attributes) will scale the image but it'll still download the whole thing. If its large that could be a problem. It's best to generate a thumbnail on upload, display that and then allow the user to click on that to display the full-size image.

cletus
+4  A: 

You can use the CSS overflow property: set it to hidden or auto to either hide content or add scrollbars if necessary.

Greg
+1  A: 

Another great one although not fully supported would be adding max-width: 400px to your image.

Shawn Simon
A: 

Instead of using CSS, you should do a basic width & height check on your server side, and if it goes beyond a certain threshold use HTML/Javascript to resize the image. Many website forum applications do this and often allow you to click to expand the image.

Then make sure you use the Z-LAYER property to make sure the image floats above content blocks so when the image expands it's above everything.

TravisO
A: 

Automatically resize each of the uploaded images, using a toolkit like ImageMagick. You'd also end up with better looking images, because it'll resample (rather than just resize).

You can then create good looking thumbnails, previews and other sizes of each images that'll fit nicely into your template designs.

codeinthehole
A: 

If you don't want to go all the way to resizing the actual image file, and want to maintain the proportions of the image, then you can interrogate the image for its sizes (height and width) then multiply them by a required factor to fit into your div.

For example, if you have a 1024x768 image and want to put it in a div that is 800 wide, you know the width will be 800, and the height will be 768 x (800/1024) = 600. Then when displaying your image you can set the height and width properties as required.

ck
Good suggestions but he did specifically ask for CSS fixes.
Joe Philllips
A: 

or, with some little piece of javascript, you can check for an image width. if is larger than Xpx, then you scale to Ypx. Ofcourse, you will have a little "image flick" until the page is completly loaded.

You can inspire yourself from any IPB forum :)

Ionut Staicu
+2  A: 
<style>img { max-width: 100% }</style>

This will make the browser resize images to fit inside their containing box. There's a few drawbacks, one being that it obviously won't work in IE6 (maybe 7?), and if the containing element has padding you'll need a wrapper around the image to make it fit.

Ant P.