The layout of text has some formatting requirements depending on the language. For example, in simplified Chinese, punctuation marks such as commas and semicolons will not appear at the beginning of a line. For English, a complete word will not be displayed on two lines. The browser will display text based on similar principles. However, due to the width limitation of web pages, continuous extra-long letters, numbers or punctuation marks exceed the width limit of the area where they are located, thus affecting the visual effect of the page, as shown in Example 1. This problem is particularly prominent when displaying user input information, and here we will talk about how to solve this problem. In the CSS3 draft, two new properties, word-wrap and word-break, are added to the text processing to solve this problem:
The following are the common browser support:
Since {word-break:break-all;} seriously reduces the readability of English and numbers and fails to wrap consecutive symbols, {word-wrap:break-word;} is a relatively good choice. But faced with such poor browser support, we have to resort to JavaScript to solve this problem, that is, when the browser does not support the CSS solution, insert ​ characters at the appropriate position of the continuous string (of course, you can also use Please see the demonstration example for specific application The fnWordBreakAll function provides some custom parameters. The usage and parameter meanings are as follows:
The core part of this function is modified from Hedger Wang's JavaScript solution "Cross Browser Word Breaker", which uses document.createTreeWalker and split method to add ​ between each character in non-IE browsers. It can be used for pure Chinese text without any problems, but if you look closely at the examples he gave, you will find that when there are English or numbers in the text, although it solves the line break problem, it makes the text difficult to read and increases the spacing between characters, so I made the above improvements on this basis. |
<<: Solution to the failure of docker windows10 shared directory mounting
>>: Explain TypeScript enumeration types in detail
First delete mysql: sudo apt-get remove mysql-* T...
1. Introduction In the past, if you wanted to sta...
Table of contents 1. What is a hook? 2. Why does ...
Docker is becoming more and more popular. It can ...
The textarea tag size is immutable Copy code The c...
The effect is very simple, just copy the following...
My page today also had garbled characters, so I s...
Preface We often need to do something based on so...
Table of contents fold (reduce) Using for...of Us...
The effect shows that two browsers simulate each ...
1. Command Introduction The seq (Sequence) comman...
1. Install the Linux system on the virtual machin...
1. Pull the Mysql image docker pull mysql:5.7 2. ...
Table of contents history pushState() Method push...
1. Complex SQL queries 1.1. Single table query (1...