0

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.
ChrisW
  • 54,973
  • 13
  • 116
  • 224
Scala_JP
  • 31
  • 2
  • 2
    Umm. ChrisW has edited your question to try to make some sense of it, but it sounds like you are asking for what is the default behaviour. – Quentin Jun 03 '10 at 08:49

2 Answers2

0

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
  • 5,108
  • 1
  • 25
  • 38
  • 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 wonderful So you see, because there is no space for 3-rd wonderful , it goes to second line – Scala_JP Jun 03 '10 at 08:58
  • I solved the problem, thanks everyone! I had too much   and that affected the way text is wrapped – Scala_JP Jun 03 '10 at 09:21
0

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.

Community
  • 1
  • 1
microspino
  • 7,693
  • 3
  • 48
  • 49