Wouldn't replacing the simple width: with max-width: 100%; do the trick? This is the CSS for image handling in a number of "responsive" website themes. That constrains the image to the size of the container, whatever size that may be.
I'm not sufficiently well-versed in these things to know whether some value for overflow needs to be invoked as well, but there are plenty of experts around! :)