This time I will show you how to set automatic line wrapping for text in web pages. How to set automatic line wrapping for text in web pages. What are the precautions? . Here is a practical case. Let’s take a look.
In a web page, it will be used to display a piece of text, but the length and content of the text are not known in advance. At this time, we mostly use the method of filling div or pre to display the text.
When using the div element, determine the width and add the following two attributes to ensure that the text filled in the div automatically wraps.
word-wrap: break-word; //word-wrap 属性允许长单词或 URL 地址换行到下一行。//break-word在长单词或 URL 地址内部进行换行。word-break: break-all;//word-break 属性规定自动换行的处理方法。
When using the pre element, similarly, add the following two attributes, and the text within it can automatically wrap.
white-space: pre-wrap; //pre-wrap保留空白符序列,但是正常地进行换行。word-break: break-all; word-wrap: break-word;
We are all familiar with divs, which can be filled with text or other elements. However, when text is placed in a div, it often cannot maintain its original format, such as spaces, carriage returns, etc. The
pre element defines preformatted text. Text enclosed in a pre element usually preserves whitespace and newlines. The text will also be rendered in a fixed-width font. A common application of the
pre tag is to represent computer source code.
Tags that can cause paragraph breaks (such as title, p, and address tags) must not be included in a block defined by pre. Although some browsers will interpret the paragraph end tag as a simple line break, this behavior is not the same in all browsers. Allowed text in pre elements can include physical styles and content-based style variations, as well as links, images, and horizontal dividers. When placing other tags (such as a tags) in the pre block, just treat it as if it were placed in other parts of the HTML/XHTML document.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to add events to button in ReactHow to use select to get the selected valueSet html to div in ReactThe above is the detailed content of How to set automatic line wrapping for text in web pages. For more information, please follow other related articles on the PHP Chinese website!