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
If you have developed DApps on Ethereum, you may ...
This article example shares the specific code for...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...
You may have set a MySQL password just now, but f...
In order to make the page display consistent betwe...
HTML+CSS 1. Understanding and knowledge of WEB st...
Preface Today I encountered a very strange proble...
Table of contents 1. Overview 2. gdb debugging 2....
This article shares the simple process of install...
When developing a backend management project, it ...
Recently, I encountered a problem in the process ...
Initialize Dockerfile Assuming our project is nam...
Table of contents 1. Resource download 2. Unzip t...
Method 1: hostnamectl modification Step 1 Check t...
1. Put the mask layer HTML code and the picture i...