Shrink wrapping a div to some text is pretty straightforward. But if the text wraps to a second line (or more) due to a max-width (as an example) then the size of the DIV do
I guess this is what you are thinking about, it can be done in css:
div { border: black solid thin; max-width: 100px; overflow: auto; }
You can see it here: http://jsfiddle.net/5epS4/