Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Automatic line-break doesn't work?

Tags:

html

css

enter

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 
like image 510
Luke Avatar asked Jul 31 '12 09:07

Luke


People also ask

How do I create an automatic line break in HTML?

Basic HTML Line Break Syntax You can insert line breaks in HTML with the <br> tag, which is equivalent to a carriage return on a keyboard. Be aware that HTML will ignore any line break from a keyboard's return key.

How do I force a line break in HTML?

To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break. Since an HTML line break is an empty element, there's no closing tag.

How do I enable line breaks?

To add spacing between lines or paragraphs of text in a cell, use a keyboard shortcut to add a new line. Click the location where you want to break the line. Press ALT+ENTER to insert the line break.

Does not line break HTML?

The <nobr> HTML element prevents the text it contains from automatically wrapping across multiple lines, potentially resulting in the user having to scroll horizontally to see the entire width of the text.


3 Answers

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 } 
like image 160
mswiszcz Avatar answered Oct 26 '22 18:10

mswiszcz


try this one by one, it must be helpful for some situation:

p{
    display: block; /* or inline-block, at least its a block element */
    width: 100px; /* or width is certain by parent element */
    height: auto; /* height cannot be defined */
    word-break: break-all; /*  */
    word-wrap: break-word; /* if you want to cut the complete word */
    white-space: normal; /* be sure its not 'nowrap'! ! ! :/ */
}
like image 5
soytian Avatar answered Oct 26 '22 18:10

soytian


another way to do it is by:

white-space: pre-wrap; // preserve whitespace, the text is wrapped
overflow-wrap: break-word; // text is wrapped, line break on the end of a word
like image 2
Eden Sharvit Avatar answered Oct 26 '22 19:10

Eden Sharvit