Search code examples
htmlcssenter

HTML Automatic line-break doesn't work?


I declared width and margins but somehow my lines didn't get wrapped with an automatic line-break.

enter image description here

edit: I found the cause. It's because there are no spaces between words:

teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest 

Solution

  • The element where text is should have css declaration:

    div {
        display: block;
        width: 200px; /*based on how much width this div should have*/
    }
    

    and if it doesn't work try doing:

    div { word-wrap: break-word }