[CSS] Forced line break

Good evening,

Do you know how to force a line break in a text inside a div? I have a div with a max-width of 510px, but if I enter a super long word, it overflows the div, and I would like to force a line break in this case. Is it possible to do this in CSS or do I need to use a script?

Thank you in advance :)
Configuration: Windows XP Safari 525.19

15 answers

  • Votes
  • Date
  • Descending date
  1. I found this property (but I can't quite get it to work). Try it and let me know if it works

    white-space
    normal: line breaks are automatic (default)
    nowrap: no automatic line breaks, unless an xHTML tag like <br /> is present.
    pre: line breaks are made as the text was entered in the source code (like the xHTML tag <pre>)
    1. Good evening, I happen to read this message quite late, but sometimes problems remain without a good solution for a long time.

      When the text becomes long in certain translations (Russian for example), word hyphenation is often necessary.
      In this case, if one wants to be very neat, one develops a template that takes into account languages by language group with a CSS for each group.

      Here, the appropriate parameter is "word-wrap:break-word;"

      As for "white-space", it allows the text to fold by generating line breaks when spaces appear;
      Obviously, if the word is longer than the line, it goes off the screen.

      See you later!
    2. Thank you!!! It was a long time ago but it’s still useful :)
    3. great !!!
    4. Thank you!! Exactly what I was looking for!
    5. Thank you very much.