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
We are all familiar with the tr command, which ca...
1. Prepare in Advance For your convenience, I cre...
1. Built-in functions 1. Mathematical functions r...
Since its release in 2013, Docker has been widely...
Students who make websites often find that some n...
1. Time formatting and other methods It is recomm...
I searched for many ways to change it online but ...
Format Encoding 1. Please set the page width with...
This article shares the installation and configur...
Preface The SQL mode affects the SQL syntax that ...
Note: Since .NET FrameWork cannot be run in core ...
Jupyter notebook is configured under the docker c...
Apache SkyWalking Apache SkyWalking is an applica...
Set Anchor Point <a name="top"><...
Preface Recently, I have been busy writing a smal...