views:

373

answers:

2

There has GOT to be a simple way to programmatically render HTML into a div tag that is width=x and have the html (along with all rendered tags and images) wrap inside the div; even if the div is inside a table or cell of width=x. But for the life of me, I can't seem to do it!

A: 

By 'programmatically', I presume you're using JavaScript to replace the contents of a DIV after the page is loaded? If the DIV is set to a hard width (via CSS or inline HTML), ensure the "overflow" CSS attribute is not set to "hidden" or "scroll". This should then wrap the HTML as per normal HTML rendering, and force the height of the DIV taller if necessary. If you have one very long line of text with no breaks, or an image that's wider than the DIV is, the DIV won't expand if you have the width specifically set.

MidnightLightning
+2  A: 

Text wraps within div tags by default. Overflow:scroll may be the source of your issue. Or it could be that your div is wider than you think it is and a good portion of it is hidden behind something else on your page.

Matthew Vines
this is what I thought originally and just spent a day coming back to this conclusion. thanks. Not sure what I was doing wrong.