views:

47

answers:

2

Hello! I have some text in div, and I want it to wrap to fit document width (without any scrolls!). I don't want to have word-break, like div {word-wrap: break-word;}

For example (this is what I want to get):

hello world! today is a 
good day.

But not:

hello world! today is a  good day.

or:

hello world! today is a go
od day.
A: 

I'm not sure what you want, is it just this?

<div style="width:200px">hello world! today is a good day.</div>
red-X
No. Width of the window can be changes as user resizes it. So, there is no fixed width. For example, if this lines are bounds:| |wonderful wonderful wonderfulSo you see, because there is no space for 3-rd wonderful , it goes to second line
Pakita
I solved the problem, thanks everyone! I had too much   and that affected the way text is wrapped
Pakita
A: 

Maybe the <wbr> tag could help you. This tag allow the browser to insert a line break where it's positioned, "if the browser want" .

This is a page were the IEbreak behavior is documented, you can take It as a model to do some debugging.

And if you want to fire-up jQuery to script-inject <wbr> in your html here you can se an example from John Resig.

You can read a complete reference about It here

A similar topic was discussed on SO here.

microspino