Heh, that sounds like something I've had to do in ebooks when fixed text needs to be aligned just so. But I did it by setting two styles, like
.floatleft {
float: left;
width: 150px;
margin:5px; }
.w180 {width: 180px;}
.w130 {width: 130px;}
.w100 {width: 100px;}
Order of CSS is crucial. The element by itself has a default width-- I set the one that occurs most often-- and then it can be overridden by other specified widths.
A floated element will limit its size to the size of its contents
But only if the content
has a width, such as an image. If it's longish text, you wouldn't want to use "auto". The validator currently likes having a "width" attribute-- but it is perfectly happy with "auto", which makes the whole thing pretty pointless ;)
If you have a whole bunch of floats, you may prefer the overall look you get from setting explicit widths. If there are just a few widely spaced images, it wouldn't make a difference. In fact in HTML4 you can use the "align" property on images and ignore the whole float thing, but in HTML5 you're not supposed to.
Experiment with using the padding property (internal to the float) instead of margin (external to the float). This is often more reliable, especially if you're floating a variety of different elements. Inline elements don't generally have margins.