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
Table of contents Preface 1. insert ignore into 2...
A must-have for interviews, you will definitely u...
I encountered a problem today: Can I use the as a...
This article shares with you how to use thinkphp5...
When customizing the installation of software, yo...
This article shares the installation and configur...
Table of contents 1. Introduction to docker-maven...
Table of contents 1. Container service update and...
Table of contents background How to determine whe...
Mysql 8.0 installation problems and password rese...
Table of contents 1. Environment Introduction 2. ...
Installation environment: CentOS7 64-bit, MySQL5....
I saw in the LOFTER competition that it was mentio...
The css animation of the rotating flip effect, th...
Table of contents Scene Introduction Plugin Imple...