CSS automatic line feed, force line break, force line break, excessive display ellipsis
P labels are automatically wrapped by default. Therefore, setting the width can achieve better results. However, recently, after loading data using ajax, the content in the p label does not have a line break, leading to layout disorder. So I tried to use the line feed style. Although the problem was solved, I did not find the essential cause. The essence is that, the data I obtained at the time was a long string of numbers. the browser should be able to process numbers in a similar way as English words without truncation.
First, various methods are provided, and then each attribute is described in detail.
Force do not wrap
P {white-space: nowrap ;}
Automatic line feed
P {word-wrap: break-word ;}
Force an English word to break a line
P {word-break: break-all ;}
* Note: to force an English word to break a line, you must set the line element to a block-level element.
The ellipsis is displayed.
P {text-overflow: ellipsis; overflow: hidden ;}
White-space: normal | pre | nowrap | pre-wrap | pre-line | inherit;
White-space attribute settings
Normal default. The blank space is ignored by the browser.
Pre blank is retained by the browser. The behavior is similar to the pre Tag in HTML.
The nowrap text will not wrap, and the text will continue on the same line until the br label is encountered.
Pre-wrap retains the blank character sequence, but line breaks are normally carried out.
Pre-line merges the blank character sequence, but retains the line break.
Inherit specifies that the value of the white-space attribute should be inherited from the parent element.
Word-wrap: normal | break-word;
The word-wrap attribute is used to indicate whether the browser is allowed to break a sentence in a word. This is to prevent overflow when a string is too long and cannot be found.
Normal)
Break-word: line feed within a long word or URL address
Word-break: normal | break-all | keep-all;
The word-break attribute is used to indicate how to break a sentence in a word.
Normal: use the default line feed rule of the browser.
Break-all: allow the next line break
Keep-all: line breaks can only be entered with halfwidth spaces or hyphens
Wordwrap: breakword; absavhsafhuafdfbjhfvsalguvfaihuivfs
Wordwrap: break-word; absavhsafhuafdfbjhfvsalguvfaihui
Wordwrap: break-word; absavhsafhuafdfbjhfvsalguvfaihuivf
Wordwrap: breakword; absavhsafhuafdfbjhfvsalguvfaihuivfsa
Wordwrap: breakword; absavhsafhuafdfbjhfvsalguvfaihuivfsab
The effect is as follows: